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:



103
104
105
106
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 103

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

#boundaryObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 108

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].odd?
  end
  factory.multi_point([array_])
end

#coordinatesObject



123
124
125
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 123

def coordinates
  @elements.map(&:coordinates)
end

#geometry_typeObject



91
92
93
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 91

def geometry_type
  Feature::MultiLineString
end

#initialize(factory_, elements_) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 81

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

#is_closed?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 95

def is_closed?
  all?(&:is_closed?)
end

#lengthObject



99
100
101
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 99

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