2012-03-06 3 views
4

GIS coveredby 쿼리 문제가 있습니다. 쿼리는 내가 검색 한 영역 밖의 좌표가있는 항목의 목록을 반환합니다.Django GIS의 coveredby 쿼리가 잘못된 결과를 반환합니다.

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. 이 코드를 테스트하려면 다음을 수행하십시오.

관련 문제