Module: RGeo::ImplHelper::BasicLineStringMethods

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#boundaryObject


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

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

#closed?Boolean

Returns:

  • (Boolean)

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

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

#contains?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

105
106
107
108
109
110
111
112
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 105

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


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

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

#dimensionObject


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

def dimension
  1
end

#empty?Boolean

Returns:

  • (Boolean)

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

def empty?
  @points.size == 0
end

#end_pointObject


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

def end_point
  @points.last
end

#geometry_typeObject


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

def geometry_type
  Feature::LineString
end

#hashObject


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

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
# 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
  validate_geometry
end

#is_closed?Boolean

Returns:

  • (Boolean)

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

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)

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

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)

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

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


22
23
24
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 22

def num_points
  @points.size
end

#point_n(n) ⇒ Object


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

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

#pointsObject


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

def points
  @points.dup
end

#rep_equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

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

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)

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

def ring?
  closed? && simple?
end

#start_pointObject


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

def start_point
  @points.first
end