readers/tfl_common.rb
# Find the nearest nodes on a given set of ways
Find the nearest nodes on a given set of ways
Find the nearest nodes on a given set of ways
def nearest_nodes(lat,lon,way_ids)
		sql = "SELECT n.id AS node_id, lat, lon, w.id AS way_id FROM planet_osm_nodes n JOIN planet_osm_ways w ON n.id=ANY(w.nodes) WHERE w.id IN (#{way_ids.join(',')})"
		nodes = $conn.exec(sql).collect { |res| { id: res['node_id'].to_i, lat: res['lat'].to_f/10000000.0, lon: res['lon'].to_f/10000000.0, way_id: res['way_id'].to_i } }
		nodes.map! { |n| n.merge(dist: FasterHaversine.distance(n[:lat],n[:lon],lat,lon)*1000) }
		nodes.sort_by { |n| n[:dist] }
	end
def nearest_nodes ( lat , lon , way_ids ) sql = "SELECT n.id AS node_id, lat, lon, w.id AS way_id FROM planet_osm_nodes n JOIN planet_osm_ways w ON n.id=ANY(w.nodes) WHERE w.id IN (#{way_ids.join(',')})" nodes = $conn . exec ( sql ) . collect { | res | { id : res [ 'node_id' ] . to_i , lat : res [ 'lat' ] . to_f / 10000000.0 , lon : res [ 'lon' ] . to_f / 10000000.0 , way_id : res [ 'way_id' ] . to_i } } nodes . map! { | n | n . merge ( dist : FasterHaversine . distance ( n [ :lat ] , n [ :lon ] , lat , lon ) * 1000 ) } nodes . sort_by { | n | n [ :dist ] } end
Find the nearest nodes on a given set of ways
Find the nearest nodes on a given set of ways
# could potentially get tags here too (from planet_osm_point) - though we'd need version to be able to write back to the database (and does it preserve everything like 'source'?)
lat
<not_specific>
lon
<not_specific>
way_ids
<not_specific>