Module: RGeo::ImplHelper::BasicLineStringMethods

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#_validate_geometryObject



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

def _validate_geometry
  if @points.size == 1
    raise Error::InvalidGeometry, 'LineString cannot have 1 point'
  end
end

#boundaryObject



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

def boundary
  array_ = []
  if !is_empty? && !is_closed?
    array_ << @points.first << @points.last
  end
  factory.multi_point([array_])
end

#dimensionObject



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

def dimension
  1
end

#end_pointObject



118
119
120
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 118

def end_point
  @points.last
end

#eql?(rhs_) ⇒ Boolean

Returns:

  • (Boolean)


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

def eql?(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_].eql?(p_) }
  else
    false
  end
end

#geometry_typeObject



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

def geometry_type
  Feature::LineString
end

#initialize(factory_, points_) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 45

def initialize(factory_, points_)
  _set_factory(factory_)
  @points = points_.map do |elem_|
    elem_ = Feature.cast(elem_, factory_, Feature::Point)
    unless elem_
      raise Error::InvalidGeometry, "Could not cast #{elem_}"
    end
    elem_
  end
  _validate_geometry
end

#is_closed?Boolean

Returns:

  • (Boolean)


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

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

#is_empty?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 99

def is_empty?
  @points.size == 0
end

#is_ring?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 131

def is_ring?
  is_closed? && is_simple?
end

#num_pointsObject



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

def num_points
  @points.size
end

#point_n(n_) ⇒ Object



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

def point_n(n_)
  @points[n_]
end

#pointsObject



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

def points
  @points.dup
end

#start_pointObject



113
114
115
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 113

def start_point
  @points.first
end