[英]Issues with POSTGIS ST_DISTANCE function and results
Using ST_DISTANCE causes a bit of confusion:使用 ST_DISTANCE 会引起一些混乱:
SELECT st_distance(
ST_SetSRID(ST_MakePoint(16.0420,45.8250), 4326),
ST_SetSRID(ST_MakePoint(16.1675,45.8344), 4326));
returns 0.12585153952177025 as an result.结果返回 0.12585153952177025。
The result seems a bit odd as on a simple visible checking those points are quite far away and result should be in meters.结果似乎有点奇怪,因为在简单的可见检查中,这些点距离很远,结果应该以米为单位。
For instance :例如 :
select st_distance(
'POINT(15.651955 73.712769 )'::geography,
'POINT(14.806993 74.131451 )'::geography) AS d;
returns 53536.74349675 which seems to work properly.返回 53536.74349675 似乎工作正常。
Can you tell me what I'm doing wrong?你能告诉我我做错了什么吗?
st_distance
returns a distance in the unit of the used coordinate system. st_distance
以所用坐标系的单位返回距离。 For 4326, the unit is degree
, so the distance is in degrees (which is meaningless).对于 4326,单位是
degree
,因此距离以度为单位(这是没有意义的)。
As you have done, you can cast to geography first, which returns a result in meters.正如您所做的那样,您可以先转换为 geography,它会以米为单位返回结果。 You can also use
ST_DistanceSpheroid
to get a distance in meters, or you can use a suitable coordinate system whose unit is in meters.您还可以使用
ST_DistanceSpheroid
获取以米为单位的距离,或者您可以使用以米为单位的合适坐标系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.