Class: GeoRuby::SimpleFeatures::LineString::Segment
- Inherits:
-
Object
- Object
- GeoRuby::SimpleFeatures::LineString::Segment
- Defined in:
- lib/georuby-ext/georuby/locators.rb
Instance Attribute Summary collapse
-
#arrival ⇒ Object
readonly
Returns the value of attribute arrival.
-
#departure ⇒ Object
readonly
Returns the value of attribute departure.
-
#line ⇒ Object
Returns the value of attribute line.
-
#line_distance_at_departure ⇒ Object
Returns the value of attribute line_distance_at_departure.
Instance Method Summary collapse
- #distance ⇒ Object
-
#initialize(departure, arrival) ⇒ Segment
constructor
A new instance of Segment.
- #interpolate_point(location) ⇒ Object
- #line_distance_at_arrival ⇒ Object
- #location_in_line ⇒ Object
- #locator(target) ⇒ Object
- #square_of_distance ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(departure, arrival) ⇒ Segment
Returns a new instance of Segment.
123 124 125 |
# File 'lib/georuby-ext/georuby/locators.rb', line 123 def initialize(departure, arrival) @departure, @arrival = departure, arrival end |
Instance Attribute Details
#arrival ⇒ Object (readonly)
Returns the value of attribute arrival.
121 122 123 |
# File 'lib/georuby-ext/georuby/locators.rb', line 121 def arrival @arrival end |
#departure ⇒ Object (readonly)
Returns the value of attribute departure.
121 122 123 |
# File 'lib/georuby-ext/georuby/locators.rb', line 121 def departure @departure end |
#line ⇒ Object
Returns the value of attribute line.
127 128 129 |
# File 'lib/georuby-ext/georuby/locators.rb', line 127 def line @line end |
#line_distance_at_departure ⇒ Object
Returns the value of attribute line_distance_at_departure.
127 128 129 |
# File 'lib/georuby-ext/georuby/locators.rb', line 127 def line_distance_at_departure @line_distance_at_departure end |
Instance Method Details
#distance ⇒ Object
147 148 149 |
# File 'lib/georuby-ext/georuby/locators.rb', line 147 def distance @distance ||= departure.spherical_distance(arrival) end |
#interpolate_point(location) ⇒ Object
155 156 157 158 159 |
# File 'lib/georuby-ext/georuby/locators.rb', line 155 def interpolate_point(location) dx, dy = (arrival.x - departure.x)*location, (arrival.y - departure.y)*location GeoRuby::SimpleFeatures::Point.from_x_y departure.x + dx, departure.y + dy, line.srid end |
#line_distance_at_arrival ⇒ Object
129 130 131 |
# File 'lib/georuby-ext/georuby/locators.rb', line 129 def line_distance_at_arrival line_distance_at_departure + distance end |
#location_in_line ⇒ Object
137 138 139 140 141 |
# File 'lib/georuby-ext/georuby/locators.rb', line 137 def location_in_line if line and line_distance_at_departure line_distance_at_departure / line.distance end end |
#locator(target) ⇒ Object
133 134 135 |
# File 'lib/georuby-ext/georuby/locators.rb', line 133 def locator(target) PointLocator.new target, self end |
#square_of_distance ⇒ Object
143 144 145 |
# File 'lib/georuby-ext/georuby/locators.rb', line 143 def square_of_distance distance**2 end |
#to_s ⇒ Object
151 152 153 |
# File 'lib/georuby-ext/georuby/locators.rb', line 151 def to_s "#{departure.x},#{departure.y}..#{arrival.x},#{arrival.y}" end |