Class: RGeo::GeoJSON::FeatureCollection

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

Methods included from ConversionMethods

#as_geojson, #to_geojson

Methods included from CollectionMethods

#contains?, #intersects?

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.

Returns:

  • (Boolean)


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

#hashObject



146
147
148
# File 'lib/rgeo/geo_json/entities.rb', line 146

def hash
  @features.hash
end

#inspectObject



138
139
140
# File 'lib/rgeo/geo_json/entities.rb', line 138

def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)}>"
end

#sizeObject

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_sObject



142
143
144
# File 'lib/rgeo/geo_json/entities.rb', line 142

def to_s
  inspect
end