Class: PNNL::BuildingId::CodeArea

Inherits:
Object
  • Object
show all
Defined in:
lib/pnnl/building_id/code_area.rb

Overview

A UBID code area.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(centroid_code_area, centroid_code_length, north_latitude, south_latitude, east_longitude, west_longitude) ⇒ CodeArea

Default constructor.

Parameters:

  • centroid_code_area (PlusCodes::CodeArea)
  • centroid_code_length (Integer)
  • north_latitude (Float)
  • south_latitude (Float)
  • east_longitude (Float)
  • west_longitude (Float)


17
18
19
20
21
22
23
24
# File 'lib/pnnl/building_id/code_area.rb', line 17

def initialize(centroid_code_area, centroid_code_length, north_latitude, south_latitude, east_longitude, west_longitude)
  @centroid_code_area = centroid_code_area
  @centroid_code_length = centroid_code_length
  @north_latitude = north_latitude
  @south_latitude = south_latitude
  @east_longitude = east_longitude
  @west_longitude = west_longitude
end

Instance Attribute Details

#centroid_code_areaObject (readonly)

Returns the value of attribute centroid_code_area.



7
8
9
# File 'lib/pnnl/building_id/code_area.rb', line 7

def centroid_code_area
  @centroid_code_area
end

#centroid_code_lengthObject (readonly)

Returns the value of attribute centroid_code_length.



7
8
9
# File 'lib/pnnl/building_id/code_area.rb', line 7

def centroid_code_length
  @centroid_code_length
end

#east_longitudeObject (readonly)

Returns the value of attribute east_longitude.



7
8
9
# File 'lib/pnnl/building_id/code_area.rb', line 7

def east_longitude
  @east_longitude
end

#north_latitudeObject (readonly)

Returns the value of attribute north_latitude.



7
8
9
# File 'lib/pnnl/building_id/code_area.rb', line 7

def north_latitude
  @north_latitude
end

#south_latitudeObject (readonly)

Returns the value of attribute south_latitude.



7
8
9
# File 'lib/pnnl/building_id/code_area.rb', line 7

def south_latitude
  @south_latitude
end

#west_longitudeObject (readonly)

Returns the value of attribute west_longitude.



7
8
9
# File 'lib/pnnl/building_id/code_area.rb', line 7

def west_longitude
  @west_longitude
end

Instance Method Details

#resizePNNL::BuildingId::CodeArea

Returns a resized version of this UBID code area, where the latitude and longitude of the lower left and upper right corners of the OLC bounding box are moved inwards by dimensions that correspond to half of the height and width of the OLC grid reference cell for the centroid.

The purpose of the resizing operation is to ensure that re-encoding a given UBID code area results in the same coordinates.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pnnl/building_id/code_area.rb', line 35

def resize
  # Calculate the (half-)dimensions of OLC grid reference cell for the
  # centroid.
  half_height = Float(@centroid_code_area.north_latitude - @centroid_code_area.south_latitude) / 2.0
  half_width = Float(@centroid_code_area.east_longitude - @centroid_code_area.west_longitude) / 2.0

  # Construct and return the new UBID code area.
  self.class.new(
    @centroid_code_area,
    @centroid_code_length,
    @north_latitude - half_height,
    @south_latitude + half_height,
    @east_longitude - half_width,
    @west_longitude + half_width
  )
end