Class: RGeo::GeoJSON::FeatureCollection
- Inherits:
-
Object
- Object
- RGeo::GeoJSON::FeatureCollection
- Includes:
- Enumerable, CollectionMethods, ConversionMethods
- Defined in:
- lib/rgeo/geo_json/entities.rb
Overview
This is a GeoJSON wrapper entity that corresponds to the GeoJSON “FeatureCollection” type. It is an immutable type.
This is the default implementation that is generated by RGeo::GeoJSON::EntityFactory. You may replace this implementation by writing your own entity factory. Note that an alternate FeatureCollection implementation need not subclass or even duck-type this class. The entity factory mediates all interaction between the GeoJSON engine and feature collections.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two feature collections are equal if they contain the same features in the same order.
-
#[](index) ⇒ Object
Access a feature by index.
-
#each(&block) ⇒ Object
Iterates or returns an iterator for the features.
-
#eql?(other) ⇒ Boolean
Two feature collections are equal if they contain the same features in the same order.
- #hash ⇒ Object
-
#initialize(features = []) ⇒ FeatureCollection
constructor
Create a new FeatureCollection with the given features, which must be provided as an Enumerable.
- #inspect ⇒ Object
-
#size ⇒ Object
Returns the number of features contained in this collection.
- #to_s ⇒ Object
Methods included from ConversionMethods
Methods included from CollectionMethods
Constructor Details
#initialize(features = []) ⇒ FeatureCollection
Create a new FeatureCollection with the given features, which must be provided as an Enumerable.
132 133 134 135 136 |
# File 'lib/rgeo/geo_json/entities.rb', line 132 def initialize(features = []) @features = [] features.each { |f| @features << f if f.is_a?(Feature) } @features.freeze end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RGeo::GeoJSON::CollectionMethods
Instance Method Details
#==(other) ⇒ Object
Two feature collections are equal if they contain the same features in the same order. This methods uses the == operator to test geometry equality, which may behave differently than the eql? method.
162 163 164 |
# File 'lib/rgeo/geo_json/entities.rb', line 162 def ==(other) other.is_a?(FeatureCollection) && @features == other.instance_variable_get(:@features) end |
#[](index) ⇒ Object
Access a feature by index.
177 178 179 |
# File 'lib/rgeo/geo_json/entities.rb', line 177 def [](index) @features[index] end |
#each(&block) ⇒ Object
Iterates or returns an iterator for the features.
167 168 169 |
# File 'lib/rgeo/geo_json/entities.rb', line 167 def each(&block) @features.each(&block) end |
#eql?(other) ⇒ Boolean
Two feature collections are equal if they contain the same features in the same order. This methods uses the eql? method to test geometry equality, which may behave differently than the == operator.
154 155 156 |
# File 'lib/rgeo/geo_json/entities.rb', line 154 def eql?(other) other.is_a?(FeatureCollection) && @features.eql?(other.instance_variable_get(:@features)) end |
#hash ⇒ Object
146 147 148 |
# File 'lib/rgeo/geo_json/entities.rb', line 146 def hash @features.hash end |
#inspect ⇒ Object
138 139 140 |
# File 'lib/rgeo/geo_json/entities.rb', line 138 def inspect "#<#{self.class}:0x#{object_id.to_s(16)}>" end |
#size ⇒ Object
Returns the number of features contained in this collection.
172 173 174 |
# File 'lib/rgeo/geo_json/entities.rb', line 172 def size @features.size end |
#to_s ⇒ Object
142 143 144 |
# File 'lib/rgeo/geo_json/entities.rb', line 142 def to_s inspect end |