Module: RGeo::Geos::FFILineStringMethods

Defined in:
lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb

Defined Under Namespace

Classes: PointLocator, Segment

Instance Method Summary collapse

Instance Method Details

#distance_from_line(target) ⇒ Object



63
64
65
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 63

def distance_from_line(target)
  nearest_locator(target).distance_from_segment
end

#distance_on_line(target) ⇒ Object



58
59
60
61
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 58

def distance_on_line(target)
  nearest_locator = nearest_locator(target)
  nearest_locator.distance_on_segment + nearest_locator.segment.line_distance_at_departure
end

#interpolate_point(location) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 100

def interpolate_point(location)
  return points.last if location >= 1
  return points.first if location <= 0

  distance_on_line = location * spherical_distance

  segment = segments.find do |segment|
    segment.line_distance_at_arrival > distance_on_line
  end

  location_on_segment =
    (distance_on_line - segment.line_distance_at_departure) / segment.distance

  segment.interpolate_point location_on_segment
end

#locate_point(target) ⇒ Object



54
55
56
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 54

def locate_point(target)
  distance_on_line(target) / length
end

#locators(point) ⇒ Object



71
72
73
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 71

def locators(point)
  segments.collect { |segment| segment.locator(point) }
end

#nearest_locator(target) ⇒ Object



67
68
69
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 67

def nearest_locator(target)
  locators(target).min_by(&:distance_from_segment)
end

#segments_with_cacheObject Also known as: segments



95
96
97
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 95

def segments_with_cache
  @segments ||= segments_without_cache
end

#segments_without_cacheObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 75

def segments_without_cache
  previous_point = nil
  distance_from_departure = 0

  
  points.inject([]) do |segments, point|
    Segment.new(previous_point, point).tap do |segment|
      segment.line = self
      segment.line_distance_at_departure = distance_from_departure

      distance_from_departure += segment.distance
      
      segments << segment
    end if previous_point
    
    previous_point = point
    segments
  end
end

#to_linear_ringObject



49
50
51
52
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 49

def to_linear_ring
  linear_ring_points = points.first == points.last ? points : points.push(points.first)
  factory.linear_ring linear_ring_points
end