姜戈& Postgis:使用 ST_Distance_sphere 进行距离查找

发布于 2024-09-07 13:46:27 字数 1194 浏览 8 评论 0原文

在 Django 文档 中,我读到了以下内容:

在除 dwithin 之外的每个距离查找中,可能会包含一个可选的第三个元素“spheroid”,以告诉 GeoDjango 在具有大地坐标系的字段上使用更准确的球体距离计算函数(例如,将使用 ST_Distance_Spheroid 而不是ST_Distance_Sphere)。

但是,当我尝试在 Postgis 1.5 数据库上使用“distance_lte”执行距离查找时,查询是使用“ST_Distance”而不是“ST_Distance_sphere”执行的。为什么 ?我是不是忘记了什么?

stations = Station.objects.filter(point__distance_lte=(pnt, D(km=10))).count()
from django.db import connection
print connection.queries

哪个打印这个:

[{'time': '0.144', 'sql': 
  'SELECT "spatial_ref_sys"."srid", "spatial_ref_sys"."auth_name", "spatial_ref_sys"."auth_srid", "spatial_ref_sys"."srtext", "spatial_ref_sys"."proj4text" FROM "spatial_ref_sys" WHERE "spatial_ref_sys"."srid" = 900913 '},
{'time': '0.903', 'sql':
  'SELECT COUNT(*) FROM "prices_station" WHERE ST_Distance("prices_station"."point", ST_GeomFromEWKB(E\'\\\\001\\\\001\\\\000\\\\000 1\\\\277\\\\015\\\\000\\\\270\\\\036\\\\205\\\\353Q\\\\270\\\\372\\\\277H\\\\341z\\\\024\\\\256\\\\007H@\'::bytea)) <= 10000.0'}]

谢谢

In Django documentation, I read this:

On every distance lookup but dwithin, an optional third element, 'spheroid', may be included to tell GeoDjango to use the more accurate spheroid distance calculation functions on fields with a geodetic coordinate system (e.g., ST_Distance_Spheroid would be used instead of ST_Distance_Sphere).

But when I try to execute a distance lookup with 'distance_lte' on a Postgis 1.5 database, the query is executed with "ST_Distance" instead of "ST_Distance_sphere". Why ? Did I forget something ?

stations = Station.objects.filter(point__distance_lte=(pnt, D(km=10))).count()
from django.db import connection
print connection.queries

Which prints this :

[{'time': '0.144', 'sql': 
  'SELECT "spatial_ref_sys"."srid", "spatial_ref_sys"."auth_name", "spatial_ref_sys"."auth_srid", "spatial_ref_sys"."srtext", "spatial_ref_sys"."proj4text" FROM "spatial_ref_sys" WHERE "spatial_ref_sys"."srid" = 900913 '},
{'time': '0.903', 'sql':
  'SELECT COUNT(*) FROM "prices_station" WHERE ST_Distance("prices_station"."point", ST_GeomFromEWKB(E\'\\\\001\\\\001\\\\000\\\\000 1\\\\277\\\\015\\\\000\\\\270\\\\036\\\\205\\\\353Q\\\\270\\\\372\\\\277H\\\\341z\\\\024\\\\256\\\\007H@\'::bytea)) <= 10000.0'}]

Thanks

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

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

发布评论

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

评论(1

一身软味 2024-09-14 13:46:27

嗯,看来你确实忘记了什么!第三个参数指定应使用球体函数。

stations = Station.objects.filter(
   point__distance_lte=(pnt,   D(km=10), True)).count()

还值得注意的是,使用 dwithin 实际上可能是更好的选择。

Well it does look like you have forgotten something! The third parameter which specifies that the spheroid function should be used.

stations = Station.objects.filter(
   point__distance_lte=(pnt,   D(km=10), True)).count()

it is also worth noting that use of dwithin might actually be the better option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文