readers/tfl_common.rb
# Fetch OSM objects near a lat/lon
Fetch OSM objects near a lat/lon
Fetch OSM objects near a lat / lon
def collect_ways(lat,lon,radius,include_foot=false)
		sql = <<-SQL
		SELECT ST_Distance( way, ST_Transform(ST_SetSRID(ST_MakePoint($1,$2),4326),3857) ) AS dist,
			   ST_Length(way) AS length,
			   ST_Azimuth(ST_StartPoint(way),ST_EndPoint(way)) AS angle,
			   hstore_to_json(tags) AS tags, osm_id
		  FROM planet_osm_line
		 WHERE highway IN (#{ROADS.collect {|r| "'"+r+"'"}.join(',') },
			 'cycleway' #{ include_foot ? ",'footway','path','track'" : "" })
		   AND ST_DWithin( way, ST_Transform(ST_SetSRID(ST_MakePoint($1,$2),4326),3857), $3 ) AND osm_id>0
	  ORDER BY dist
		SQL
		$conn.exec_params(sql,[lon,lat,radius]).collect { |res| { 
			id: res['osm_id'].to_i, tags: JSON.parse(res['tags'] || '{}'), dist: res['dist'].to_f,
			angle: res['angle'].to_f, length: res['length'].to_f
		} }
	end
def collect_ways ( lat , lon , radius , include_foot = false ) sql = <<-SQL 
		SELECT ST_Distance( way, ST_Transform(ST_SetSRID(ST_MakePoint($1,$2),4326),3857) ) AS dist,
			   ST_Length(way) AS length,
			   ST_Azimuth(ST_StartPoint(way),ST_EndPoint(way)) AS angle,
			   hstore_to_json(tags) AS tags, osm_id
		  FROM planet_osm_line
		 WHERE highway IN ( #{ ROADS . collect { | r | "'" + r + "'" } . join ( ',' ) } ,
			 'cycleway'  #{ include_foot ? ",'footway','path','track'" : "" } )
		   AND ST_DWithin( way, ST_Transform(ST_SetSRID(ST_MakePoint($1,$2),4326),3857), $3 ) AND osm_id>0
	  ORDER BY dist
		 SQL $conn . exec_params ( sql , [ lon , lat , radius ] ) . collect { | res | { id : res [ 'osm_id' ] . to_i , tags : JSON . parse ( res [ 'tags' ] || '{}' ) , dist : res [ 'dist' ] . to_f , angle : res [ 'angle' ] . to_f , length : res [ 'length' ] . to_f } } end
Fetch OSM objects near a lat/lon
Fetch OSM objects near a lat / lon
lat
<not_specific>
lon
<not_specific>
radius
<not_specific>
include_foot
<not_specific>