class Aerospike::GeoJSON
Wrapper for GeoJSON
data. GeoJSON
data needs to be wrapped to allow the client to distinguish geospatial data from string (or hash) data. Geospatial data from a record’s bin will be returned as an instance of this class. The wrapper accepts GeoJSON
data either as a String or a Hash.
Attributes
json_data[RW]
Public Class Methods
circle(lng, lat, radius)
click to toggle source
# File lib/aerospike/geo_json.rb, line 103 def self.circle(lng, lat, radius) new(type: 'AeroCircle', coordinates: [[lng, lat], radius]) end
new(data)
click to toggle source
# File lib/aerospike/geo_json.rb, line 30 def initialize(data) self.json_data = case data when String data else data.to_json end end
point(lng, lat)
click to toggle source
# File lib/aerospike/geo_json.rb, line 99 def self.point(lng, lat) new(type: 'Point', coordinates: [lng, lat]) end
polygon(coordinates)
click to toggle source
# File lib/aerospike/geo_json.rb, line 107 def self.polygon(coordinates) new(type: 'Polygon', coordinates: coordinates) end
Public Instance Methods
==(other)
click to toggle source
# File lib/aerospike/geo_json.rb, line 50 def ==(other) return false unless other.class == self.class other.to_json == self.to_json end
circle?()
click to toggle source
# File lib/aerospike/geo_json.rb, line 91 def circle? type == 'AeroCircle' end
coordinates()
click to toggle source
# File lib/aerospike/geo_json.rb, line 79 def coordinates to_h['coordinates'] end
lat()
click to toggle source
# File lib/aerospike/geo_json.rb, line 64 def lat case type when 'Point' coordinates.last when 'AeroCircle' coordinates.first.last end end
lng()
click to toggle source
# File lib/aerospike/geo_json.rb, line 55 def lng case type when 'Point' coordinates.first when 'AeroCircle' coordinates.first.first end end
point?()
click to toggle source
# File lib/aerospike/geo_json.rb, line 87 def point? type == 'Point' end
polygon?()
click to toggle source
# File lib/aerospike/geo_json.rb, line 95 def polygon? type == 'Polygon' end
radius()
click to toggle source
# File lib/aerospike/geo_json.rb, line 73 def radius return nil unless circle? coordinates.last end
to_circle(radius)
click to toggle source
# File lib/aerospike/geo_json.rb, line 111 def to_circle(radius) raise TypeError, 'Cannot create a Circle from a Polygon' if polygon? self.class.circle(lng, lat, radius) end
to_hash()
click to toggle source
# File lib/aerospike/geo_json.rb, line 45 def to_hash JSON.parse(json_data) end
Also aliased as: to_h
to_json()
click to toggle source
# File lib/aerospike/geo_json.rb, line 40 def to_json json_data end
Also aliased as: to_s
to_point()
click to toggle source
# File lib/aerospike/geo_json.rb, line 117 def to_point return self if point? raise TypeError, 'Cannot create a Point from a Polygon' if polygon? self.class.point(lng, lat) end
type()
click to toggle source
# File lib/aerospike/geo_json.rb, line 83 def type to_h['type'] end