Skip to content

Instantly share code, notes, and snippets.

@jatorre
jatorre / gist:1678789
Created January 25, 2012 21:21
Find the intersection for a latitude and longitude
--First, this is quick hack ported from https://github.com/fruminator/openstreetblock/
--Replace the latitude and longitude accordly on the different places and encode the whole SQL or it will not work
http://vizzuality.cartodb.com/api/v1/sql?q=
select l.name, l.osm_id from osm_line l join way_nodes wn on l.osm_id = wn.way_id where wn.node_id = ( select n.id from nodes n where ARRAY[n.id::integer] && (select w.nodes from osm_line l join osm_ways w on l.osm_id = w.id where st_intersects(way , ST_buffer(ST_SetSRID(ST_MakePoint(-73.999548,40.71954),4326), .002)) order by way <-> ST_SetSRID(ST_MakePoint(-73.999548,40.71954),4326) limit 1) order by n.geom <-> ST_SetSRID(ST_MakePoint(-73.999548,40.71954),4326) limit 1) and wn.way_id != ( select osm_id from osm_line l join osm_ways w on l.osm_id = w.id where st_intersects(way, ST_buffer(ST_SetSRID(ST_MakePoint(-73.999548,40.71954),4326), .002) ) LIMIT 1) and l.name is not null and l.name != ''