Skip to content

Instantly share code, notes, and snippets.

@laacz
Created May 19, 2012 08:19
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save laacz/2730058 to your computer and use it in GitHub Desktop.
Save laacz/2730058 to your computer and use it in GitHub Desktop.
PostGIS: Find nearest roads (represented by linestring) to a given point
/*
* Road data comes from OpenStreetmap (http://download.geofabrik.de/osm/)
**/
select st_distance(st_closestpoint(r.the_geog::geometry, wa.location::geometry), wa.location::geometry) as cp
, r.name
, r.ref
, r.ogc_fid
, r.type
, st_astext(wa.location)
, wa.*
from points_of_interest wa, roads r
where wa.id = 'some-poi-id'
and (r.name is not null or r.ref is not null)
order by cp asc
limit 10
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment