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



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 101

def boundary
  hash = {}
  @elements.each do |line|
    if !line.empty? && !line.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

#closed?Boolean

Returns:

  • (Boolean)


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

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

#contains?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


120
121
122
123
124
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 120

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

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

#coordinatesObject



116
117
118
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 116

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

#geometry_typeObject



89
90
91
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 89

def geometry_type
  Feature::MultiLineString
end

#initialize(factory, elements) ⇒ Object



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

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
  init_geometry
end

#lengthObject



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

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