【发布时间】:2012-03-06 07:39:39
【问题描述】:
有一个GIS被查询覆盖的问题,查询返回一个项目列表,这些项目的坐标在我搜索过的区域之外,这是怎么回事?
from django.contrib.gis.geos import Polygon
from deals.models import Deal
x1, y1 = 37.446899, 55.693455
x2, y2 = 37.666626, 55.551165
area = Polygon(((x1, y1), (x2, y1), (x2, y2), (x1, y2), (x1, y1)))
qs = Deal.objects.filter(locations__coords__coveredby=area)
def count():
ok, failed = 0, 0
for item in qs.filter(locations__coords__isnull=False)[:20]:
for loc in item.locations.all():
lon = loc.longitude
lat = loc.latitude
if x1 <= lon <= x2 and y1 <= lat <= y2:
ok += 1
else:
failed += 1
return ok, failed
>>> ok, failed
Out[18]: (0, 11)
【问题讨论】: