class RGeo::GeoJSON::EntityFactory

This is the default entity factory. It creates objects of type RGeo::GeoJSON::Feature and RGeo::GeoJSON::FeatureCollection. You may create your own entity factory by duck-typing this class.

Public Class Methods

instance() click to toggle source

Return the singleton instance of EntityFactory.

# File lib/rgeo/geo_json/entities.rb, line 221
def self.instance
  @instance ||= new
end

Public Instance Methods

feature(geometry, id = nil, properties = nil) click to toggle source

Create and return a new feature, given geometry, ID, and properties hash. Note that, per the GeoJSON spec, geometry and/or properties may be nil.

# File lib/rgeo/geo_json/entities.rb, line 168
def feature(geometry, id = nil, properties = nil)
  Feature.new(geometry, id, properties || {})
end
feature_collection(features = []) click to toggle source

Create and return a new feature collection, given an enumerable of feature objects.

# File lib/rgeo/geo_json/entities.rb, line 175
def feature_collection(features = [])
  FeatureCollection.new(features)
end
get_feature_geometry(object) click to toggle source

Returns the geometry associated with the given feature.

# File lib/rgeo/geo_json/entities.rb, line 202
def get_feature_geometry(object)
  object.geometry
end
get_feature_id(object) click to toggle source

Returns the ID of the given feature, or nil for no ID.

# File lib/rgeo/geo_json/entities.rb, line 208
def get_feature_id(object)
  object.feature_id
end
get_feature_properties(object) click to toggle source

Returns the properties of the given feature as a hash. Editing this hash does not change the state of the feature.

# File lib/rgeo/geo_json/entities.rb, line 215
def get_feature_properties(object)
  object.properties
end
is_feature?(object) click to toggle source

Returns true if the given object is a feature created by this entity factory.

# File lib/rgeo/geo_json/entities.rb, line 182
def is_feature?(object)
  object.is_a?(Feature)
end
is_feature_collection?(object) click to toggle source

Returns true if the given object is a feature collection created by this entity factory.

# File lib/rgeo/geo_json/entities.rb, line 189
def is_feature_collection?(object)
  object.is_a?(FeatureCollection)
end
map_feature_collection(object, &block) click to toggle source

Run Enumerable#map on the features contained in the given feature collection.

# File lib/rgeo/geo_json/entities.rb, line 196
def map_feature_collection(object, &block)
  object.map(&block)
end