Postgis - st_distance

发布于 2024-11-15 00:33:01 字数 307 浏览 2 评论 0原文

我在使用 postgis 中的 st_distance 函数时遇到问题。它返回错误的结果 - 对于小距离,误差并不大 - 10,也许 20 米,但对于较大的距离,我的结果和例如谷歌地图结果之间的差异太大 - 700 米到 2 公里甚至更高。我正在使用 srid = 4326。第二件事 - 也许这就是问题所在 - 假设我有一个 4 公里外的地方。 Postgis 表示距离大约 0.0417 {{some_units}}。现在我只是将结果乘以 100 并得到或多或少准确的结果。我可以向此函数传递一些参数,表示“返回值以公里/米为单位”吗?

附: postgres 版本是 9.0.1

I'm having problems with st_distance function in postgis. It returns wrongs results - for small distances the error isn't big - 10, maybe 20 meters but for bigger distances the difference between my results and for example google maps results are too big - 700 meters up to 2 kilometers and higher. I'm using srid = 4326. And second thing - maybe that's the problem - say I've got place that's 4 kilometers away. Postgis says it's ~ 0.0417 {{some_units}} away. Right now I'm just multiplying the result by 100 and get more or less accurate results. Can I pass some argument to this function that would say "return value in kilometers/meters"?

ps. postgres version is 9.0.1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

筑梦 2024-11-22 00:33:01

您应该使用地理数据类型。

使用几何数据类型使用的函数,您将获得与存储数据相同的单位。在您的情况下是度。

度不能以任何简单的方式转换为米。为了从未投影的参考系获得以米为单位的结果,计算需要在围绕地球面的“大圆”上进行计算。您使用的计算只是使用毕达哥拉斯定理来计算平面上的距离。

所以,PostGIS 不会给出错误的结果。
您可以移动到基于米的空间参考系统,具体取决于您的数据是否覆盖那么大的区域,因此地球的圆角是一个问题,如果是这样,您应该使用地理数据类型并使用 srid

4326。HTH

Nicklas

You should use the geography data type.

With the function used by the geometry datatype you will get the same unit back as the data is stored in. In your case degrees.

degrees can not be translated to meters in any easy way. To get the result in meters from an unprojected reference system the calculation need to calculate on the "great circle" around the sheroid of the earth. The calculation you are using is just using Pythagoras theorem to calculate the distance on a plane.

So, PostGIS doesn't give wrong result.
You could move to a meter based spatial reference system depending on if your data cover that big area so the rounding of the globe is an issue, If so you should use the geography data type instead and use srid 4326.

HTH

Nicklas

夜声 2024-11-22 00:33:01

你应该使用你的投影,目前它以度为单位,如果你想以米为单位使用 ST_transform 如下所示:

    ST_Distance(st_transform(ST_GeometryFromText('POINT(longitude     latitude)',4326),900913),st_transform(point,900913)) 

you should use your projection, for the moment it is in degrees if you want in meter use ST_transform like this :

    ST_Distance(st_transform(ST_GeometryFromText('POINT(longitude     latitude)',4326),900913),st_transform(point,900913)) 
甜`诱少女 2024-11-22 00:33:01

您应该按照 cyril 所说的操作,将您的几何图形转换为使用距离单位为米的 srid,例如 900913。将您现在得到的度数(使用 srid=4326)乘以 100 并不是正确的方法。

根据您所在的位置,可能有一个以米为单位的本地 srid 更适合您所在的位置 - 例如,瑞士的 SRID 是 21781。另请检查:http://gothos.info/tag/coefficient-systems/ 适用于美国地区的一些 srid。

You should do what cyril said and transform your geometries to use a srid with distance units in meters, such as 900913. Multiplying what you get right now in degrees (using srid=4326) by 100 is not the way to go.

Depending on where you are, there may be a local srid in meters that is more accurate for your location -- for instance, the SRID for Switzerland is 21781. Check this also: http://gothos.info/tag/coordinate-systems/ for some srids in the US area.

给我一枪 2024-11-22 00:33:01

详细说明尼克拉斯的答案,鉴于您的所有几何图形都有 srid 4326,您可以使用:

select st_distance(geom1::geography,geom2::geography)

获取以米为单位的距离

或者,为了更准确,将几何图形转换为特定于区域的投影 crs,例如 EPSG:25832 ETRS89 / UTM zone 32N :

select st_distance(st_transform(geom1,25832),st_transform(geom2,25832))

Detailing Nicklas'answer, given that all your geoms have srid 4326, you can use:

select st_distance(geom1::geography,geom2::geography)

to get the distance in meters

Or, to be more accurate, tranform the geometries to a region-specific projected crs like EPSG:25832 ETRS89 / UTM zone 32N:

select st_distance(st_transform(geom1,25832),st_transform(geom2,25832))
南烟 2024-11-22 00:33:01

SRID:4326即WGS1984是用纬度和经度来表示世界坐标。所以当你想测量距离时,你必须在UTM中投影。你可以参考

空间引用系统

数据库中的 表可查看哪个 SRID 使用哪个单位。
要测量,请将其投影到 UTM。您可以使用 utmzone 函数找到所需的 utm 区域。然后您可以使用下面的查询。

select st_distance(st_transform(geom1,utmzone(geom1)),st_transform(geom2,utmzone(geom2)))

SRID:4326 ie.WGS1984 is to represent the world co ordinates in latitude and longitude.So when u want to measure distances, u have to project in UTM.You can refer the

spatial_ref_sys

table in your database to see which SRID uses which unit.
To measure u project it to UTM.You can find the required utm zone using the utmzone function.then u can use the below query.

select st_distance(st_transform(geom1,utmzone(geom1)),st_transform(geom2,utmzone(geom2)))
债姬 2024-11-22 00:33:01

如果你有数据作为萨尔的几何答案很好。如果您有经纬度数据,请尝试以下操作:

select st_distance(point1,point2) from 
(SELECT ST_GeogFromText('SRID=4326;POINT(0 0)') point1,  
ST_GeogFromText('SRID=4326;POINT(0.25 0.4)') point2) a

If you have data as geom answer of sal is good. If you have data as lat long then try this:

select st_distance(point1,point2) from 
(SELECT ST_GeogFromText('SRID=4326;POINT(0 0)') point1,  
ST_GeogFromText('SRID=4326;POINT(0.25 0.4)') point2) a
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文