Class: RGeo::GeoJSON::EntityFactory

Inherits:
Object
  • Object
show all
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 Method Summary collapse

Class Method Details

.instanceObject

Return the singleton instance of EntityFactory.


258
259
260
# File 'lib/rgeo/geo_json/entities.rb', line 258

def self.instance
  @instance ||= self.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.


197
198
199
# File 'lib/rgeo/geo_json/entities.rb', line 197

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.


205
206
207
# File 'lib/rgeo/geo_json/entities.rb', line 205

def feature_collection(features_=[])
  FeatureCollection.new(features_)
end

#get_feature_geometry(object_) ⇒ Object

Returns the geometry associated with the given feature.


236
237
238
# File 'lib/rgeo/geo_json/entities.rb', line 236

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.


243
244
245
# File 'lib/rgeo/geo_json/entities.rb', line 243

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.


251
252
253
# File 'lib/rgeo/geo_json/entities.rb', line 251

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.

Returns:

  • (Boolean)

213
214
215
# File 'lib/rgeo/geo_json/entities.rb', line 213

def is_feature?(object_)
  object_.kind_of?(Feature)
end

#is_feature_collection?(object_) ⇒ Boolean

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

Returns:

  • (Boolean)

221
222
223
# File 'lib/rgeo/geo_json/entities.rb', line 221

def is_feature_collection?(object_)
  object_.kind_of?(FeatureCollection)
end

#map_feature_collection(object_, &block_) ⇒ Object

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


229
230
231
# File 'lib/rgeo/geo_json/entities.rb', line 229

def map_feature_collection(object_, &block_)
  object_.map(&block_)
end