Created
October 6, 2017 08:51
-
-
Save halfdan/a35414aba92a81680aa37cb342c93164 to your computer and use it in GitHub Desktop.
Distance between two locations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
*, | |
ST_Distance( | |
"geom", | |
ST_Transform( | |
'0101000020E6100000E54350357A995EC0CA8745B181E34240', -- Value of a geom in the same table | |
2163 | |
) | |
) AS "distance" | |
FROM "zoning_source_locations" | |
ORDER BY "distance" DESC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE zoning_source_locations ( | |
id integer NOT NULL, | |
name text, | |
type text, | |
geom geometry(Point,4326) | |
); | |
# Data inserted via | |
INSERT INTO zoning_source_locations VALUES ( | |
"McDonals", "restaurant", ST_SetSRID(ST_MakePoint(lng, lat), 4326) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Getting the following error when executing query.sql:
I'm trying to retrieve the distance between the hard coded point and all stored geom(s) in meters.