Class: RGeo::Geos::FFILineStringMethods::PointLocator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, segment_or_departure, arrival = nil) ⇒ PointLocator

Returns a new instance of PointLocator.



165
166
167
168
169
170
171
172
173
174
175
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 165

def initialize(target, segment_or_departure, arrival = nil)
  @segment = 
    if arrival
      Segment.new(segment_or_departure, arrival)
    else
      segment_or_departure
    end
  @target = target
  @factory = departure.factory
  raise "Target is not defined" unless target
end

Instance Attribute Details

#factoryObject (readonly)

Returns the value of attribute factory.



162
163
164
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 162

def factory
  @factory
end

#segmentObject (readonly)

Returns the value of attribute segment.



162
163
164
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 162

def segment
  @segment
end

#targetObject (readonly)

Returns the value of attribute target.



162
163
164
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 162

def target
  @target
end

Instance Method Details

#distance_from_segmentObject



181
182
183
184
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 181

def distance_from_segment
  return 0 if [segment.departure, segment.arrival].include?(target)          
  target_distance_from_segment
end

#distance_on_segmentObject



177
178
179
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 177

def distance_on_segment          
  Math.sqrt( target_distance_from_departure**2 - target_distance_from_segment**2 )
end

#target_distance_from_departureObject



186
187
188
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 186

def target_distance_from_departure
  departure.distance target
end

#target_distance_from_segmentObject



190
191
192
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 190

def target_distance_from_segment
  target.distance(factory.line_string([segment.departure, segment.arrival]))
end