Skip to content

Instantly share code, notes, and snippets.

@halfdan
Created October 6, 2017 08:51
Show Gist options
  • Save halfdan/a35414aba92a81680aa37cb342c93164 to your computer and use it in GitHub Desktop.
Save halfdan/a35414aba92a81680aa37cb342c93164 to your computer and use it in GitHub Desktop.
Distance between two locations
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;
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)
);
@halfdan
Copy link
Author

halfdan commented Oct 6, 2017

Getting the following error when executing query.sql:

ERROR: function st_transform(unknown, integer) is not unique

I'm trying to retrieve the distance between the hard coded point and all stored geom(s) in meters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment