2012-03-06 7 views
4

GISの覆われたクエリの問題があります。クエリは、検索した領域外の座標を持つアイテムのリストを返します。Django 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) 

答えて

0

解決策は単純です:

x1, y1 = 'left bottom corner of rectangle area' 
x2, y2 = 'top right corner of rectangle area' 
area = Polygon.from_bbox((x1, y1, x2, y2)) 

P.S.このコードをテストして確認してください:)

関連する問題