Class: RGeo::GeoJSON::FeatureCollection

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

Constructor Details

#initialize(features_ = []) ⇒ FeatureCollection

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


123
124
125
126
# File 'lib/rgeo/geo_json/entities.rb', line 123

def initialize(features_=[])
  @features = []
  features_.each{ |f_| @features << f_ if f_.kind_of?(Feature) }
end

Instance Method Details

#==(rhs_) ⇒ 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.


157
158
159
# File 'lib/rgeo/geo_json/entities.rb', line 157

def ==(rhs_)
  rhs_.kind_of?(FeatureCollection) && @features == rhs_.instance_variable_get(:@features)
end

#[](index_) ⇒ Object

Access a feature by index.


178
179
180
# File 'lib/rgeo/geo_json/entities.rb', line 178

def [](index_)
  @features[index_]
end

#each(&block_) ⇒ Object

Iterates or returns an iterator for the features.


164
165
166
# File 'lib/rgeo/geo_json/entities.rb', line 164

def each(&block_)
  @features.each(&block_)
end

#eql?(rhs_) ⇒ 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)

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

def eql?(rhs_)
  rhs_.kind_of?(FeatureCollection) && @features.eql?(rhs_.instance_variable_get(:@features))
end

#hashObject

:nodoc:


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

def hash  # :nodoc:
  @features.hash
end

#inspectObject

:nodoc:


129
130
131
# File 'lib/rgeo/geo_json/entities.rb', line 129

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

#sizeObject

Returns the number of features contained in this collection.


171
172
173
# File 'lib/rgeo/geo_json/entities.rb', line 171

def size
  @features.size
end

#to_sObject

:nodoc:


133
134
135
# File 'lib/rgeo/geo_json/entities.rb', line 133

def to_s  # :nodoc:
  inspect
end