姜戈& Postgis:使用 ST_Distance_sphere 进行距离查找
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,看来你确实忘记了什么!第三个参数指定应使用球体函数。
还值得注意的是,使用 dwithin 实际上可能是更好的选择。
Well it does look like you have forgotten something! The third parameter which specifies that the spheroid function should be used.
it is also worth noting that use of dwithin might actually be the better option.