Class: RGeo::GeoJSON::EntityFactory
- Inherits:
-
Object
- Object
- RGeo::GeoJSON::EntityFactory
- Defined in:
- lib/rgeo/geo_json/entities.rb
Overview
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.
Class Method Summary collapse
-
.instance ⇒ Object
Return the singleton instance of EntityFactory.
Instance Method Summary collapse
-
#feature(geometry, id = nil, properties = nil) ⇒ Object
Create and return a new feature, given geometry, ID, and properties hash.
-
#feature_collection(features = []) ⇒ Object
Create and return a new feature collection, given an enumerable of feature objects.
-
#get_feature_geometry(object) ⇒ Object
Returns the geometry associated with the given feature.
-
#get_feature_id(object) ⇒ Object
Returns the ID of the given feature, or nil for no ID.
-
#get_feature_properties(object) ⇒ Object
Returns the properties of the given feature as a hash.
-
#is_feature?(object) ⇒ Boolean
Returns true if the given object is a feature created by this entity factory.
-
#is_feature_collection?(object) ⇒ Boolean
Returns true if the given object is a feature collection created by this entity factory.
-
#map_feature_collection(object, &block) ⇒ Object
Run Enumerable#map on the features contained in the given feature collection.
Class Method Details
.instance ⇒ Object
Return the singleton instance of EntityFactory.
235 236 237 |
# File 'lib/rgeo/geo_json/entities.rb', line 235 def self.instance @instance ||= new end |
Instance Method Details
#feature(geometry, id = nil, properties = nil) ⇒ Object
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.
190 191 192 |
# File 'lib/rgeo/geo_json/entities.rb', line 190 def feature(geometry, id = nil, properties = nil) Feature.new(geometry, id, properties || {}) end |
#feature_collection(features = []) ⇒ Object
Create and return a new feature collection, given an enumerable of feature objects.
196 197 198 |
# File 'lib/rgeo/geo_json/entities.rb', line 196 def feature_collection(features = []) FeatureCollection.new(features) end |
#get_feature_geometry(object) ⇒ Object
Returns the geometry associated with the given feature.
219 220 221 |
# File 'lib/rgeo/geo_json/entities.rb', line 219 def get_feature_geometry(object) object.geometry end |
#get_feature_id(object) ⇒ Object
Returns the ID of the given feature, or nil for no ID.
224 225 226 |
# File 'lib/rgeo/geo_json/entities.rb', line 224 def get_feature_id(object) object.feature_id end |
#get_feature_properties(object) ⇒ Object
Returns the properties of the given feature as a hash. Editing this hash does not change the state of the feature.
230 231 232 |
# File 'lib/rgeo/geo_json/entities.rb', line 230 def get_feature_properties(object) object.properties end |
#is_feature?(object) ⇒ Boolean
Returns true if the given object is a feature created by this entity factory.
202 203 204 |
# File 'lib/rgeo/geo_json/entities.rb', line 202 def is_feature?(object) object.is_a?(Feature) end |
#is_feature_collection?(object) ⇒ Boolean
Returns true if the given object is a feature collection created by this entity factory.
208 209 210 |
# File 'lib/rgeo/geo_json/entities.rb', line 208 def is_feature_collection?(object) object.is_a?(FeatureCollection) end |
#map_feature_collection(object, &block) ⇒ Object
Run Enumerable#map on the features contained in the given feature collection.
214 215 216 |
# File 'lib/rgeo/geo_json/entities.rb', line 214 def map_feature_collection(object, &block) object.map(&block) end |