class RGeo::GeoJSON::Feature

This is a GeoJSON wrapper entity that corresponds to the GeoJSON “Feature” type. It is an immutable type.

This is the default implementation that is generated by RGeo::GeoJSON::EntityFactory. You may replace this implementation by writing your own entity factory. Note that an alternate Feature implementation need not subclass or even duck-type this class. the entity factory mediates all interaction between the GeoJSON engine and features.

Attributes

geometry[R]

Returns the geometry contained in this feature, which may be nil.

Public Class Methods

new(geometry, id = nil, properties = {}) click to toggle source

Create a feature wrapping the given geometry, with the given ID and properties.

# File lib/rgeo/geo_json/entities.rb, line 19
def initialize(geometry, id = nil, properties = {})
  @geometry = geometry
  @id = id
  @properties = {}
  properties.each do |k, v|
    @properties[k.to_s] = v
  end
end

Public Instance Methods

==(other) click to toggle source

Two features are equal if their geometries, IDs, and properties are all equal. This method uses the == operator to test geometry equality, which may behave differently than the eql? method.

# File lib/rgeo/geo_json/entities.rb, line 54
def ==(other)
  other.is_a?(Feature) && @geometry == other.geometry && @id == other.feature_id && @properties == other.instance_variable_get(:@properties)
end
[](key)
Alias for: property
eql?(other) click to toggle source

Two features are equal if their geometries, IDs, and properties are all equal. This method uses the eql? method to test geometry equality, which may behave differently than the == operator.

# File lib/rgeo/geo_json/entities.rb, line 45
def eql?(other)
  other.is_a?(Feature) && @geometry.eql?(other.geometry) && @id.eql?(other.feature_id) && @properties.eql?(other.instance_variable_get(:@properties))
end
feature_id() click to toggle source

Returns the ID for this feature, which may be nil.

# File lib/rgeo/geo_json/entities.rb, line 64
def feature_id
  @id
end
hash() click to toggle source
# File lib/rgeo/geo_json/entities.rb, line 36
def hash
  @geometry.hash + @id.hash + @properties.hash
end
inspect() click to toggle source
# File lib/rgeo/geo_json/entities.rb, line 28
def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)} id=#{@id.inspect} geom=#{@geometry ? @geometry.as_text.inspect : 'nil'}>"
end
keys() click to toggle source

Gets an array of the known property keys in this feature.

# File lib/rgeo/geo_json/entities.rb, line 84
def keys
  @properties.keys
end
properties() click to toggle source

Returns a copy of the properties for this feature.

# File lib/rgeo/geo_json/entities.rb, line 70
def properties
  @properties.dup
end
property(key) click to toggle source

Gets the value of the given named property. Returns nil if the given property is not found.

# File lib/rgeo/geo_json/entities.rb, line 77
def property(key)
  @properties[key.to_s]
end
Also aliased as: []
to_s() click to toggle source
# File lib/rgeo/geo_json/entities.rb, line 32
def to_s
  inspect
end