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.
221 222 223 |
# File 'lib/rgeo/geo_json/entities.rb', line 221 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.
168 169 170 |
# 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 = []) ⇒ Object
Create and return a new feature collection, given an enumerable of feature objects.
175 176 177 |
# File 'lib/rgeo/geo_json/entities.rb', line 175 def feature_collection(features = []) FeatureCollection.new(features) end |
#get_feature_geometry(object) ⇒ Object
Returns the geometry associated with the given feature.
202 203 204 |
# File 'lib/rgeo/geo_json/entities.rb', line 202 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.
208 209 210 |
# File 'lib/rgeo/geo_json/entities.rb', line 208 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.
215 216 217 |
# File 'lib/rgeo/geo_json/entities.rb', line 215 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.
182 183 184 |
# File 'lib/rgeo/geo_json/entities.rb', line 182 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.
189 190 191 |
# File 'lib/rgeo/geo_json/entities.rb', line 189 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.
196 197 198 |
# File 'lib/rgeo/geo_json/entities.rb', line 196 def map_feature_collection(object, &block) object.map(&block) end |