2012-10-27 48 views
1

我在我的开发环境中使用在SpatiaLite上运行的GeoDjango进行地理查询时遇到问题。GeoDjango:基本地理查询的例外

from django.contrib.gis.db import models 

class Test(models.Model): 
    poly = models.PolygonField() 
    point = models.PointField() 
    geom = models.GeometryField() 
    objects = models.GeoManager() 

测试通过shell:

>>> from geotest.models import Test 
>>> from django.contrib.gis.geos import GEOSGeometry 
>>> 
>>> point = GEOSGeometry("POINT(0 0)") 
>>> point 
<Point object at 0x105743490> 
>>> poly = GEOSGeometry("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))") 
>>> poly 
<Polygon object at 0x105743370> 
>>> 

有了这些定义,让我们尝试一些基本的地理查询。第一个contains

>>> Test.objects.filter(point__within=poly) 
Assertion failed: (0), function appendGeometryTaggedText, file WKTWriter.cpp, line 228. 
Abort trap 

而django外壳死亡。并与within

>>> Test.objects.filter(poly__contains=point) 
GEOS_ERROR: Geometry must be a Point or LineString 
Traceback (most recent call last): 
... 
GEOSException: Error encountered checking Coordinate Sequence returned from GEOS C function "GEOSGeom_getCoordSeq_r". 
>>> 

其他组合也会导致各种例外。我必须错过一些明显的东西,因为这些都是非常基本的有任何想法吗?

回答