Class: GeoRuby::SimpleFeatures::LineString
- Inherits:
-
Object
- Object
- GeoRuby::SimpleFeatures::LineString
show all
- Defined in:
- lib/georuby-ext/georuby/line_string.rb,
lib/georuby-ext/georuby/locators.rb
Defined Under Namespace
Classes: PointLocator, Segment
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.merge(lines) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/georuby-ext/georuby/line_string.rb', line 19
def self.merge(lines)
merged_points = lines.map(&:points).flatten.uniq
if merged_points.size > 1
from_points merged_points, lines.first.srid, lines.first.with_z, lines.first.with_m
end
end
|
Instance Method Details
#==(other) ⇒ Object
30
31
32
|
# File 'lib/georuby-ext/georuby/line_string.rb', line 30
def ==(other)
other.respond_to?(:points) and points == other.points
end
|
#change(options) ⇒ Object
3
4
5
6
7
8
9
|
# File 'lib/georuby-ext/georuby/line_string.rb', line 3
def change(options)
self.class.from_points(options[:points] || points,
options[:srid] || srid,
options[:with_z] || with_z,
options[:with_m] || with_m)
end
|
#distance ⇒ Object
96
97
98
|
# File 'lib/georuby-ext/georuby/locators.rb', line 96
def distance
segments.sum(&:distance)
end
|
#distance_from_line(target) ⇒ Object
67
68
69
|
# File 'lib/georuby-ext/georuby/locators.rb', line 67
def distance_from_line(target)
nearest_locator(target).distance_from_segment
end
|
#distance_on_line(target) ⇒ Object
62
63
64
65
|
# File 'lib/georuby-ext/georuby/locators.rb', line 62
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/georuby/locators.rb', line 100
def interpolate_point(location)
return points.last if location >= 1
return points.first if location <= 0
distance_on_line = location * 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
58
59
60
|
# File 'lib/georuby-ext/georuby/locators.rb', line 58
def locate_point(target)
distance_on_line(target) / distance
end
|
#locators(point) ⇒ Object
75
76
77
|
# File 'lib/georuby-ext/georuby/locators.rb', line 75
def locators(point)
segments.collect { |segment| segment.locator(point) }
end
|
#nearest_locator(target) ⇒ Object
71
72
73
|
# File 'lib/georuby-ext/georuby/locators.rb', line 71
def nearest_locator(target)
locators(target).min_by(&:distance_from_segment)
end
|
#reverse ⇒ Object
11
12
13
|
# File 'lib/georuby-ext/georuby/line_string.rb', line 11
def reverse
change :points => points.reverse
end
|
#segments ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/georuby-ext/georuby/locators.rb', line 79
def segments
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 = segments.sum(&:distance)
segments << segment
end if previous_point
previous_point = point
segments
end
end
|
#to_rgeo ⇒ Object
26
27
28
|
# File 'lib/georuby-ext/georuby/line_string.rb', line 26
def to_rgeo
RGeo::Geos::factory(:srid => srid).line_string(points.collect(&:to_rgeo))
end
|
#to_ring ⇒ Object
36
37
38
39
|
# File 'lib/georuby-ext/georuby/line_string.rb', line 36
def to_ring
ring_points = closed? ? points : points + [first]
GeoRuby::SimpleFeatures::LinearRing.from_points ring_points, srid, with_z, with_m
end
|
#to_wgs84 ⇒ Object
15
16
17
|
# File 'lib/georuby-ext/georuby/line_string.rb', line 15
def to_wgs84
change :points => points.map(&:to_wgs84), :srid => 4326
end
|