class RGeo::GeoJSON::FeatureCollection

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.

Public Class Methods

new(features = []) click to toggle source

Create a new FeatureCollection with the given features, which must be provided as an Enumerable.

# File lib/rgeo/geo_json/entities.rb, line 105
def initialize(features = [])
  @features = []
  features.each { |f| @features << f if f.is_a?(Feature) }
end

Public Instance Methods

==(other) click to toggle source

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.

# File lib/rgeo/geo_json/entities.rb, line 136
def ==(other)
  other.is_a?(FeatureCollection) && @features == other.instance_variable_get(:@features)
end
[](index) click to toggle source

Access a feature by index.

# File lib/rgeo/geo_json/entities.rb, line 154
def [](index)
  @features[index]
end
each(&block) click to toggle source

Iterates or returns an iterator for the features.

# File lib/rgeo/geo_json/entities.rb, line 142
def each(&block)
  @features.each(&block)
end
eql?(other) click to toggle source

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.

# 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() click to toggle source
# File lib/rgeo/geo_json/entities.rb, line 118
def hash
  @features.hash
end
inspect() click to toggle source
# File lib/rgeo/geo_json/entities.rb, line 110
def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)}>"
end
size() click to toggle source

Returns the number of features contained in this collection.

# File lib/rgeo/geo_json/entities.rb, line 148
def size
  @features.size
end
to_s() click to toggle source
# File lib/rgeo/geo_json/entities.rb, line 114
def to_s
  inspect
end