Module: RGeo::ImplHelper::BasicMultiLineStringMethods

Included in:
Cartesian::MultiLineStringImpl, Geographic::ProjectedMultiLineStringImpl, Geographic::SphericalMultiLineStringImpl
Defined in:
lib/rgeo/impl_helper/basic_geometry_collection_methods.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#_add_boundary(hash_, point_) ⇒ Object

:nodoc:


162
163
164
165
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 162

def _add_boundary(hash_, point_)  # :nodoc:
  hval_ = [point_.x, point_.y].hash
  (hash_[hval_] ||= [point_, 0])[1] += 1
end

#boundaryObject


168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 168

def boundary
  hash_ = {}
  @elements.each do |line_|
    if !line_.is_empty? && !line_.is_closed?
      _add_boundary(hash_, line_.start_point)
      _add_boundary(hash_, line_.end_point)
    end
  end
  array_ = []
  hash_.each do |hval_, data_|
    array_ << data_[0] if data_[1] % 2 == 1
  end
  factory.multi_point([array_])
end

#geometry_typeObject


147
148
149
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 147

def geometry_type
  Feature::MultiLineString
end

#initialize(factory_, elements_) ⇒ Object


134
135
136
137
138
139
140
141
142
143
144
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 134

def initialize(factory_, elements_)
  _set_factory(factory_)
  @elements = elements_.map do |elem_|
    elem_ = Feature.cast(elem_, factory_, Feature::LineString, :keep_subtype)
    unless elem_
      raise Error::InvalidGeometry, "Could not cast #{elem_}"
    end
    elem_
  end
  _validate_geometry
end

#is_closed?Boolean

Returns:

  • (Boolean)

152
153
154
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 152

def is_closed?
  all?{ |elem_| elem_.is_closed? }
end

#lengthObject


157
158
159
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 157

def length
  @elements.inject(0.0){ |sum_, obj_| sum_ + obj_.length }
end