Reputation: 21
Can someone tell me why this keeps returning degrees instead of meters? I’m transforming the geometry SRID to 32613, which measures in meters. Thanks
SELECT storm_date, hail_size_inches,
ST_Distance(
ST_Transform(geom32613, 32613),
ST_SetSRID(
ST_MakePoint(-104.89907, 39.66643),
32613)
) distance
FROM hail.hail_swaths
WHERE storm_date >= '2021/06/01'
Upvotes: 2
Views: 291
Reputation: 17906
You are using lat-long coordinates (4326) as if they were in 32613.
ST_SetSRID(ST_MakePoint(-104.89907, 39.66643), 32613)
--> replace with ST_Transform(ST_SetSRID(ST_MakePoint(-104.89907, 39.66643), 4326),32613);
Also double check what values are stored in the column geom32613
. If they are indeed in 32613, there is no need to reproject them
Example for 1 degree, near the central meridian for this projection:
SELECT ST_Distance(ST_Transform('SRID=4326;POINT(-105 40)',32613),
jgtest(> ST_Transform('SRID=4326;POINT(-106 40)',32613));
st_distance
------------------
85361.8049211818
Upvotes: 2
Reputation: 19653
Welcome to SO.
Your problem might be somewhere else. ST_Distance
with two geometries using the SRS 32613 returns the distance in metres:
SELECT ST_Distance('SRID=32613;POINT(508654.55672303465 4390740.143711988)',
'SRID=32613;POINT(508654.55672303480 4390740.143711988)');
st_distance
----------------------
1.74622982740402e-10
(1 row)
It also works using ST_Transform
SELECT ST_Distance(
ST_Transform('SRID=4326;POINT(-104.89910 39.66643)',32613),
ST_Transform('SRID=4326;POINT(-104.89907 39.66643)',32613));
st_distance
------------------
2.57321026907276
(1 row)
Demo: db<>fiddle
Are you perhaps mixing the order of the coordinate pairs? Remember, it is longitude, latitude, not the other way around. If the geometries are correct, please post a WKT literal from both geometries, so that we can reproduce your environment. Another option would be to use geography
instead of geometry
, which would automatically return the result in metres, but you would need to transform the geometries encoded in 32613 in a lon/lat coordinate system to make the cast work, such as 4326.
EDIT: Read carefully the answer of @JGH - he might have found the real issue. You're probably using the coordinates with a wrong SRS!
Upvotes: 1