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
Return the singleton instance of EntityFactory
.
# File lib/rgeo/geo_json/entities.rb, line 221 def self.instance @instance ||= new end
Public Instance Methods
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
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
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
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
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
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
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
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