Module: RGeo::ImplHelper::BasicLineStringMethods

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#boundaryObject



50
51
52
53
54
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 50

def boundary
  array = []
  array << @points.first << @points.last if !empty? && !closed?
  factory.multipoint([array])
end

#closed?Boolean

Returns:

  • (Boolean)


64
65
66
67
68
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 64

def closed?
  return @closed if defined?(@closed)

  @closed = @points.size > 2 && @points.first == @points.last
end

#contains?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
93
94
95
96
97
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 90

def contains?(rhs)
  if Feature::Point === rhs
    contains_point?(rhs)
  else
    raise(Error::UnsupportedOperation,
          "Method LineString#contains? is only defined for Point")
  end
end

#coordinatesObject



86
87
88
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 86

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

#dimensionObject



38
39
40
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 38

def dimension
  1
end

#empty?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 46

def empty?
  @points.size == 0
end

#end_pointObject



60
61
62
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 60

def end_point
  @points.last
end

#geometry_typeObject



42
43
44
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 42

def geometry_type
  Feature::LineString
end

#hashObject



82
83
84
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 82

def hash
  @hash ||= [factory, geometry_type, *@points].hash
end

#initialize(factory, points) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 12

def initialize(factory, points)
  self.factory = factory
  @points = points.map do |elem|
    elem = Feature.cast(elem, factory, Feature::Point)
    raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
    elem
  end
  # LineStrings in general need to check that there's not one point
  # GEOS doesn't allow instantiation of single point LineStrings so
  # we should handle it.
  raise Error::InvalidGeometry, "LineString Cannot Have 1 Point" if @points.size == 1
  init_geometry
end

#num_pointsObject



26
27
28
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 26

def num_points
  @points.size
end

#point_n(idx) ⇒ Object



30
31
32
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 30

def point_n(idx)
  idx < 0 ? nil : @points[idx]
end

#pointsObject



34
35
36
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 34

def points
  @points.dup
end

#rep_equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
80
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 74

def rep_equals?(rhs)
  if rhs.is_a?(self.class) && rhs.factory.eql?(@factory) && @points.size == rhs.num_points
    rhs.points.each_with_index { |p, i| return false unless @points[i].rep_equals?(p) }
  else
    false
  end
end

#ring?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 70

def ring?
  closed? && simple?
end

#start_pointObject



56
57
58
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 56

def start_point
  @points.first
end