Module: RGeo::ImplHelper::BasicLineStringMethods

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#_copy_state_from(obj_) ⇒ Object

:nodoc:



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

def _copy_state_from(obj_) # :nodoc:
  super
  @points = obj_.points
end

#_validate_geometryObject



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

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

#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 !is_empty? && !is_closed?
  factory.multi_point([array_])
end

#coordinatesObject



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

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

#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



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

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



10
11
12
13
14
15
16
17
18
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 10

def initialize(factory_, points_)
  _set_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)


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

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)


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

def is_empty?
  @points.size == 0
end

#is_ring?Boolean

Returns:

  • (Boolean)


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

def is_ring?
  is_closed? && is_simple?
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(n_) ⇒ Object



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

def point_n(n_)
  n_ < 0 ? nil : @points[n_]
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)


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

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

#start_pointObject



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

def start_point
  @points.first
end