Skip to content

Instantly share code, notes, and snippets.

@kevinmcmahon
Created January 9, 2012 21:50
Show Gist options
  • Select an option

  • Save kevinmcmahon/1585140 to your computer and use it in GitHub Desktop.

Select an option

Save kevinmcmahon/1585140 to your computer and use it in GitHub Desktop.
Spatial query to find 5 closest landmarks to a lat/long in Chicago
-- distance units in planar degrees. 4326 is WGS 84 and the long lat units are degrees
SELECT
ST_Distance(ST_GeomFromText('POINT(-87.6348345 41.8786207)', 4326), landmarks.the_geom) AS planar_degrees,
name,
architect
FROM landmarks
ORDER BY planar_degrees ASC
LIMIT 5;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment