Class: RGeo::GeoJSON::FeatureCollection
- Inherits:
-
Object
- Object
- RGeo::GeoJSON::FeatureCollection
- Includes:
- Enumerable
- 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
Constructor Details
#initialize(features = []) ⇒ FeatureCollection
Create a new FeatureCollection with the given features, which must be provided as an Enumerable.
105 106 107 108 |
# File 'lib/rgeo/geo_json/entities.rb', line 105 def initialize(features = []) @features = [] features.each { |f| @features << f if f.is_a?(Feature) } end |
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.
136 137 138 |
# File 'lib/rgeo/geo_json/entities.rb', line 136 def ==(other) other.is_a?(FeatureCollection) && @features == other.instance_variable_get(:@features) end |
#[](index) ⇒ Object
Access a feature by index.
154 155 156 |
# File 'lib/rgeo/geo_json/entities.rb', line 154 def [](index) @features[index] end |
#each(&block) ⇒ Object
Iterates or returns an iterator for the features.
142 143 144 |
# File 'lib/rgeo/geo_json/entities.rb', line 142 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.
127 128 129 |
# File 'lib/rgeo/geo_json/entities.rb', line 127 def eql?(other) other.is_a?(FeatureCollection) && @features.eql?(other.instance_variable_get(:@features)) end |
#hash ⇒ Object
118 119 120 |
# File 'lib/rgeo/geo_json/entities.rb', line 118 def hash @features.hash end |
#inspect ⇒ Object
110 111 112 |
# File 'lib/rgeo/geo_json/entities.rb', line 110 def inspect "#<#{self.class}:0x#{object_id.to_s(16)}>" end |
#size ⇒ Object
Returns the number of features contained in this collection.
148 149 150 |
# File 'lib/rgeo/geo_json/entities.rb', line 148 def size @features.size end |
#to_s ⇒ Object
114 115 116 |
# File 'lib/rgeo/geo_json/entities.rb', line 114 def to_s inspect end |