I'm running into some repeated problems in my geodjango apps that seem to be originating with GEOS. I am receiving errors that do not include stack trace information so I'm not sure how to go about debugging them. I've been able to isolate the issue to specific commands that utilize GEOS.
UPDATE: below is an even simpler test case that gives me an error. I doubt this would give you an error, and I strongly suspect this is related to my machine, my environment, or my build of GEOS. Any tips on how to work through this are greatly appreciated.
>>> 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".
Here's a breakdown of the kinds of errors I am encountering
>>> 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".
Any ideas on how I can resolve or debug this situation? Thanks!
Please note that the problem is NOT particular to that polygon. If I pick any other feature I receive the same errors.
Here's the stats on the environment:
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"
I've install GEOS and GDAL using the KyngChaos binaries and have them on my system path
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
[EDIT: by request, the geometry directly from the database as WKT]