GeoDjango,dwithin和distance_lt之间的区别? [英] GeoDjango, difference between dwithin and distance_lt?
问题描述
使用geoDjango,
myObj.objects.filter(point__dwithin(...等))有什么区别?
和
myObj.objects.filter(point__distance_lt(...等))
?< br>
他们是相同的事情,还是做细微的不同的事情?
好的,我做了一些研究,但我不知道结果是否有任何用途;)
-
我看着单元测试但是他们没有提供真正的提示(对我来说)。
-
我试图比较生成的SQL:
我已经有一个使用 PostgreSQL 数据库的地理应用程序。当我使用 __ distance_lt
执行此查询时:
Place.objects.filter(location__distance_lt =(p.location,D(km = 1)))。query.as_sql()
我得到这个生成的SQL:
SELECT(some_fields_here)
FROMplaces_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:只有地理DWithin查询才允许使用度数单位的数值。
所以我不得不将查询更改为不使用 D
对象:
Place.objects.filter(location__dwithin =(p.location, 1))。query.as_sql()
导致
SELECT(这里的某些字段)
FROMplaces_place
WHERE ST_DWithin(places_place。location,%s,1)
摘要: p>
__ dwithin
- 以度数值作为距离参数。 br>
- 使用 ST_DWithin
SQL函数。
__ distance_lt
- 可以采取其他距离值;)。
- 使用 ST_distance_sphere
SQL函数。
Btw,我得到与两个查询不同的结果,但我猜这主要是因为我不知道要使用哪个度值。
Using geoDjango, what is the difference between
myObj.objects.filter(point__dwithin(...etc.))
and
myObj.objects.filter(point__distance_lt(...etc.))
?
Are they the same thing, or are they doing subtly different things?
Ok, I did some research but I don't know if the results are of any use ;)
I looked at the unit tests that they use to test the DB queries but they don't give real hints (to me).
I tried to compare the generated SQL:
I have already a geo application using a PostgreSQL databse. When I perform this query with __distance_lt
:
Place.objects.filter(location__distance_lt=(p.location, D(km=1))).query.as_sql()
I get this generated SQL:
SELECT (some_fields_here)
FROM "places_place"
WHERE ST_distance_sphere("places_place"."location", %s) < 1000.0
When I try to use do to the same with __dwithin
, I get an error:
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.
So I had to change the query to no use a D
object:
Place.objects.filter(location__dwithin=(p.location, 1)).query.as_sql()
which results in
SELECT (some fields here)
FROM "places_place"
WHERE ST_DWithin("places_place"."location", %s, 1)
Summary:
__dwithin
- takes degree values as distance parameter.
- uses ST_DWithin
SQL function.
__distance_lt
- can take other distance values ;).
- uses ST_distance_sphere
SQL function.
Btw, I get different results with both queries but I guess this is mostly due the fact that I don't know which "degree" value to use.
这篇关于GeoDjango,dwithin和distance_lt之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!