3

我在我的 geodjango 应用程序中遇到了一些重复的问题,这些问题似乎源于 GEOS。我收到不包含堆栈跟踪信息的错误,因此我不确定如何调试它们。我已经能够将问题隔离到使用 GEOS 的特定命令上。

更新:下面是一个更简单的测试用例,它给了我一个错误。我怀疑这会给你一个错误,我强烈怀疑这与我的机器、我的环境或我的 GEOS 构建有关。非常感谢有关如何解决此问题的任何提示。

>>> from django.contrib.gis.geos import Polygon, MultiPolygon
>>> p1 = Polygon( ((0, 0), (0, 1), (1, 1), (0, 0)) )
GEOS_ERROR: Shell is not a LinearRing
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/benjamin/projects/artgeese/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.py", line 42, in __init__
    polygon = self._create_polygon(n_holes + 1, (ext_ring,) + init_holes)
  File "/Users/benjamin/projects/artgeese/lib/python2.7/site-packages/django/contrib/gis/geos/polygon.py", line 85, in _create_polygon
    return capi.create_polygon(shell, holes_param, c_uint(n_holes))
  File "/Users/benjamin/projects/artgeese/lib/python2.7/site-packages/django/contrib/gis/geos/prototypes/threadsafe.py", line 49, in __call__
    return self.cfunc(self.thread_context.handle.ptr, *args)
  File "/Users/benjamin/projects/artgeese/lib/python2.7/site-packages/django/contrib/gis/geos/prototypes/errcheck.py", line 43, in check_geom
    raise GEOSException('Error encountered checking Geometry returned from GEOS C function "%s".' % func.__name__)
GEOSException: Error encountered checking Geometry returned from GEOS C function "GEOSGeom_createPolygon_r".

这是我遇到的各种错误的细分

>>> basins = GroundWater.objects.all()
>>> geoms = [b.geom() for b in basins]
>>> geom = geoms[3]
>>> print type( geom )
<class 'django.contrib.gis.geos.collections.MultiPolygon'>

>>> polygon = geom.cascading_union # this is ok
>>> print type( polygon )
<class 'django.contrib.gis.geos.polygon.Polygon'>

>>> print polygon
# this receives the following error and shuts down the dev server
Assertion failed: (0), function appendGeometryTaggedText, file WKTWriter.cpp,
line 228.
Abort trap

>>> print polygon.num_interior_rings 
# causes an error, does not stop the server
GEOS_ERROR: Argument is not a Polygon
and
Error encountered in GEOS C function "GEOSGetNumInteriorRings_r".

>>> print polygon.coords
# causes an error, does not stop the server
GEOS_ERROR: Argument is not a Polygon
and
Error encountered in GEOS C function "GEOSGetNumInteriorRings_r".

>>> print polygon.valid
GEOS_ERROR: UnsupportedOperationException: 
Error encountered on GEOS C predicate function "GEOSisValid_r".

关于如何解决或调试这种情况的任何想法?谢谢!

请注意,该问题并非特定于该多边形。如果我选择任何其他功能,我会收到相同的错误。

以下是环境统计数据:

Mac OS X==10.6.8
Python==2.7.1
Django==1.4.2
psycopg2==2.4.5

                                         postgis_full_version                                          
---------------------------------------------------------------------------------
 POSTGIS="1.5.1" GEOS="3.2.2-CAPI-1.6.2" PROJ="Rel. 4.7.1, 23 September 2009" LIBXML="2.7.3"

我已经使用 KyngChaos 二进制文件安装了 GEOS 和 GDAL,并将它们放在我的系统路径上

export PATH=/Library/Frameworks/GDAL.framework/Versions/1.9/Python/site-packages:$PATH
export PATH=/Library/Frameworks/UnixImageIO.framework/Programs:$PATH
export PATH=/Library/Frameworks/PROJ.framework/Programs:$PATH
export PATH=/Library/Frameworks/GEOS.framework/Programs:$PATH
export PATH=/Library/Frameworks/SQLite3.framework/Programs:$PATH
export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH
export PATH=/usr/local/pgsql/bin:$PATH

[编辑:根据要求,直接从数据库中获取几何图形作为 WKT ]

4

0 回答 0