Class: RubyVolt::DataType::GeographyPoint

Inherits:
FixedSize show all
Defined in:
lib/ruby_volt/data_type/basic/fixed_size/geography_point.rb

Constant Summary collapse

DIRECTIVE =
"G2"
LENGTH =
16

Class Method Summary collapse

Methods inherited from Basic

bytesToInt, intToBytes

Methods inherited from RubyVolt::DataType

classifyDataType, testpacking, voltDataType

Class Method Details

.pack(point) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/ruby_volt/data_type/basic/fixed_size/geography_point.rb', line 8

def pack(point)
  # A GeographyPointValue's wire protocol representation is simply two double precision numbers in sequence. The first is the longitude, and must be in the range -180 ≤ longitude ≤ 180. The second is the latitude, and must be in the range -90 ≤ latitude ≤ 90. The null GeographyPoint value has longitude and latitude both equal to 360.0.
  if point.nil?
    lng, lat = 360.0, 360.0
  else
    lng, lat = point.lng, point.lat
  end
  [lng, lat].pack(self::DIRECTIVE)
end

.unpack(bytes) ⇒ Object



18
19
20
21
22
23
# File 'lib/ruby_volt/data_type/basic/fixed_size/geography_point.rb', line 18

def unpack(bytes)
  lng, lat = *bytes.read(self::LENGTH).unpack(self::DIRECTIVE)
  if (lng != 360.0) && (lat != 360.0)
    Meta::Geography::Point.new(lng, lat)
  end
end