Class: GeoRuby::SimpleFeatures::LineString::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/georuby-ext/georuby/locators.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#arrivalObject (readonly)

Returns the value of attribute arrival.



121
122
123
# File 'lib/georuby-ext/georuby/locators.rb', line 121

def arrival
  @arrival
end

#departureObject (readonly)

Returns the value of attribute departure.



121
122
123
# File 'lib/georuby-ext/georuby/locators.rb', line 121

def departure
  @departure
end

#lineObject

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_departureObject

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

#distanceObject



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_arrivalObject



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_lineObject



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_distanceObject



143
144
145
# File 'lib/georuby-ext/georuby/locators.rb', line 143

def square_of_distance
  distance**2
end

#to_sObject



151
152
153
# File 'lib/georuby-ext/georuby/locators.rb', line 151

def to_s
  "#{departure.x},#{departure.y}..#{arrival.x},#{arrival.y}"
end