使用geoDjango,两者有什么区别
myObj.objects.filter(point__dwithin(...etc.))
和
myObj.objects.filter(point__distance_lt(...etc.))
它们是同一件事,还是在做微妙的不同的事情?
发布于 2010-02-10 20:33:17
好吧,我做了一些研究,但我不知道结果是否有用;)
我已经有了一个使用PostgreSQL数据库的地理应用程序。当我使用__distance_lt
执行此查询时
Place.objects.filter(location__distance_lt=(p.location, D(km=1))).query.as_sql()
我得到了这个生成的SQL:
SELECT (some_fields_here)
FROM "places_place"
WHERE ST_distance_sphere("places_place"."location", %s) < 1000.0
当我尝试对__dwithin
,执行相同的操作时,我得到了一个错误:
Place.objects.filter(location__dwithin=(p.location, D(km=1))).query.as_sql()
TypeError: Only numeric values of degree units are allowed on geographic DWithin queries.
因此,我不得不将查询更改为不使用D
对象:
Place.objects.filter(location__dwithin=(p.location, 1)).query.as_sql()
这导致了
SELECT (some fields here)
FROM "places_place"
WHERE ST_DWithin("places_place"."location", %s, 1)
摘要:
__dwithin
ST_DWithin
函数。
__distance_lt
ST_distance_sphere
SQL函数。顺便说一句,我用两个查询得到了不同的结果,但我猜这主要是因为我不知道使用哪个“度”值。
https://stackoverflow.com/questions/2235043
复制相似问题