[gdal-dev] Pickling OGR Geometry

Jason Beverage jasonbeverage at gmail.com
Wed Mar 16 11:24:54 EDT 2011


Hi all,

I'm looking at pickling ogr geometry.  I took the following code from
the gdal autotests to try it out:

geom_wkt = 'MULTIPOLYGON( ((0 0,1 1,1 0,0 0)),((0 0,10 0, 10 10, 0
10),(1 1,1 2,2 2,2 1)) )'
geom = ogr.CreateGeometryFromWkt(geom_wkt)
p = pickle.dumps(geom)
g = pickle.loads(p)
if not geom.Equal(g):
    print "pickled geometries were not equal"
else:
    print "pickled geometries equal"

The geometries are equal and appears to work fine but I get an error
printed out right after the loads call:
ERROR 1: Empty geometries cannot be constructed

If I do ogr.UseExceptions() I get the stack trace:
Traceback (most recent call last):
  File "test.py", line 32, in <module>
    g = pickle.loads(p)
  File "/usr/lib/python2.6/pickle.py", line 1374, in loads
    return Unpickler(file).load()
  File "/usr/lib/python2.6/pickle.py", line 858, in load
    dispatch[key](self)
  File "/usr/lib/python2.6/pickle.py", line 1133, in load_reduce
    value = func(*args)
  File "/usr/local/lib/python2.6/dist-packages/GDAL-1.7.2-py2.6-linux-x86_64.egg/osgeo/ogr.py",
line 2935, in __init__
    this = _ogr.new_Geometry(*args, **kwargs)
RuntimeError: Empty geometries cannot be constructed


Is this a problem or is it just noise?  I'm using GDAL 1.7.2.

Thanks,

Jason


More information about the gdal-dev mailing list