Module: RGeo::ImplHelper::BasicLineStringMethods

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#boundaryObject


57
58
59
60
61
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 57

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

#closed?Boolean

Returns:

  • (Boolean)

71
72
73
74
75
76
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 71

def closed?
  unless defined?(@closed)
    @closed = @points.size > 2 && @points.first == @points.last
  end
  @closed
end

#contains?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

111
112
113
114
115
116
117
118
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 111

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


107
108
109
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 107

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

#dimensionObject


40
41
42
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 40

def dimension
  1
end

#empty?Boolean

Returns:

  • (Boolean)

48
49
50
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 48

def empty?
  @points.size == 0
end

#end_pointObject


67
68
69
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 67

def end_point
  @points.last
end

#geometry_typeObject


44
45
46
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 44

def geometry_type
  Feature::LineString
end

#hashObject


100
101
102
103
104
105
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 100

def hash
  @hash ||= begin
    hash = [factory, geometry_type].hash
    @points.inject(hash) { |h, p| (1_664_525 * h + p.hash).hash }
  end
end

#initialize(factory, points) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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.
  if @points.size == 1
    raise Error::InvalidGeometry, "LineString Cannot Have 1 Point"
  end
  init_geometry
end

#is_closed?Boolean

Returns:

  • (Boolean)

78
79
80
81
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 78

def is_closed?
  warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
  closed?
end

#is_empty?Boolean

Returns:

  • (Boolean)

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

def is_empty?
  warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
  empty?
end

#is_ring?Boolean

Returns:

  • (Boolean)

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

def is_ring?
  warn "The is_ring? method is deprecated, please use the ring? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
  ring?
end

#num_pointsObject


28
29
30
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 28

def num_points
  @points.size
end

#point_n(n) ⇒ Object


32
33
34
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 32

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

#pointsObject


36
37
38
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 36

def points
  @points.dup
end

#rep_equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

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

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)

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

def ring?
  closed? && simple?
end

#start_pointObject


63
64
65
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 63

def start_point
  @points.first
end