Class: RGeo::Geos::FFILineStringMethods::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(departure, arrival) ⇒ Segment

Returns a new instance of Segment.



120
121
122
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 120

def initialize(departure, arrival)
  @departure, @arrival = departure, arrival
end

Instance Attribute Details

#arrivalObject (readonly)

Returns the value of attribute arrival.



118
119
120
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 118

def arrival
  @arrival
end

#departureObject (readonly)

Returns the value of attribute departure.



118
119
120
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 118

def departure
  @departure
end

#lineObject

Returns the value of attribute line.



124
125
126
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 124

def line
  @line
end

#line_distance_at_departureObject

Returns the value of attribute line_distance_at_departure.



124
125
126
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 124

def line_distance_at_departure
  @line_distance_at_departure
end

Instance Method Details

#distanceObject



144
145
146
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 144

def distance
  @distance ||= departure.distance(arrival)
end

#interpolate_point(location) ⇒ Object



152
153
154
155
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 152

def interpolate_point(location)
  dx, dy = (arrival.x - departure.x) * location, (arrival.y - departure.y) * location
  RGeo::Geos::FFIPoint.from_x_y departure.x + dx, departure.y + dy, line.srid
end

#line_distance_at_arrivalObject



126
127
128
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 126

def line_distance_at_arrival
  line_distance_at_departure + distance
end

#location_in_lineObject



134
135
136
137
138
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 134

def location_in_line
  if line and line_distance_at_departure
    line_distance_at_departure / line.length
  end
end

#locator(target) ⇒ Object



130
131
132
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 130

def locator(target)
  PointLocator.new target, self
end

#square_of_distanceObject



140
141
142
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 140

def square_of_distance
  distance**2
end

#to_sObject



148
149
150
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 148

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