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



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

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

#distance_on_line(target) ⇒ Object



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

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



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 95

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



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

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

#locators(point) ⇒ Object



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

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

#nearest_locator(target) ⇒ Object



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

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

#segments_with_cacheObject Also known as: segments



90
91
92
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 90

def segments_with_cache
  @segments ||= segments_without_cache
end

#segments_without_cacheObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 70

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



44
45
46
47
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 44

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