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

#boundaryObject


104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 104

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.multipoint([array])
end

#contains?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

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

def contains?(rhs)
  return super unless Feature::Point === rhs

  @elements.any? { |line| line.contains?(rhs) }
end

#coordinatesObject


119
120
121
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 119

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

#geometry_typeObject


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

def geometry_type
  Feature::MultiLineString
end

#initialize(factory, elements) ⇒ Object


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

def initialize(factory, elements)
  self.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)

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

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

#lengthObject


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

def length
  @elements.inject(0.0) { |sum, obj| sum + obj.length }
end