4

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]

Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49
BenjaminGolder
  • 1,573
  • 5
  • 19
  • 37
  • Can you share the geometries? Just select directly from database, using WKT. – George Silva Jan 02 '13 at 17:55
  • @George : I've edited the answer and included a link to the geometry. I posted it [as a gist](https://gist.github.com/4436552). – BenjaminGolder Jan 02 '13 at 18:11
  • @George I should also mention that I seem to run into these errors with _any_ geometry that I use. It does not appear to be related to any particular geometry. – BenjaminGolder Jan 02 '13 at 18:25
  • 1
    Did you ever solve this? This error has recently started effecting an app of mine seemingly out of the blue, but in my case it is very hard to replicate. It is happening sometimes when I test if a point is within a polygon. – Alexander Dec 23 '15 at 13:13
  • @alex honestly I don't remember what I did back then, but I think I would have posted here if I figured out how to solve it. If I encountered this again today, I would probably rebuild the environment, using fresh installs of GEOS and other C dependencies, postgres, and a fresh python virtualenv. It seems likely to be connected to the environment or built C libraries. – BenjaminGolder Dec 25 '15 at 00:11
  • 1
    Thanks Benjamin, in my case things (without any reason I could work out) started working again before I did anything to try to fix them... most mysterious. – Alexander Jan 18 '16 at 18:02

0 Answers0