Class: GeoRuby::GeojsonFeature

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_ruby/geojson.rb

Overview

Class added to support geojson ‘Feature’ objects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(geometry, properties = {}, id = nil) ⇒ GeojsonFeature

Returns a new instance of GeojsonFeature.



12
13
14
15
16
# File 'lib/geo_ruby/geojson.rb', line 12

def initialize(geometry, properties = {}, id = nil)
  @geometry = geometry
  @properties = properties
  @id = id
end

Instance Attribute Details

#geometryObject

Returns the value of attribute geometry.



10
11
12
# File 'lib/geo_ruby/geojson.rb', line 10

def geometry
  @geometry
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/geo_ruby/geojson.rb', line 10

def id
  @id
end

#propertiesObject

Returns the value of attribute properties.



10
11
12
# File 'lib/geo_ruby/geojson.rb', line 10

def properties
  @properties
end

Instance Method Details

#==(other) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/geo_ruby/geojson.rb', line 18

def ==(other)
  if (self.class != other.class)
    false
  else
    (self.id == other.id) && (self.geometry == other.geometry) && (self.properties == other.properties)
  end
end

#to_json(options = {}) ⇒ Object Also known as: as_geojson



26
27
28
29
30
31
32
33
# File 'lib/geo_ruby/geojson.rb', line 26

def to_json(options={})
  output = {}
  output[:type] = 'Feature'
  output[:geometry] = geometry
  output[:properties] = properties
  output[:id] = id unless id.nil?
  output.to_json(options)
end