[FWTools] Python object serialization (pickle) of OGRGeometry

Frank Warmerdam warmerdam at pobox.com
Mon Feb 12 13:45:28 EST 2007

Jack L. Riley wrote:
> Hello Frank et al,
> I have a Python (v2.3.5-based) application which stores OGR feature 
> geometry objects (<OGRFeature>.GetGeometryRef().Clone()) in a dict.  To 
> support pickling of these OGRGeometry instances (w/o spatial reference 
> system), I added the following __getstate__ and __setstate__ methods to 
> ogr.y:
>   def __getstate__(self):
>       return self.ExportToWkb()
>   def __setstate__(self, state):
>       result = CreateGeometryFromWkb(state)
>       self._o = result._o
>       self.thisown = result.thisown
>       result.thisown = 0
> Note that a similar thing was done in Python Cartographic Library's 
> geometry.py--see trac changeset 411:
> http://trac.gispython.org/projects/PCL/changeset/411
> Might this be included in future releases of FWTools/ogr.py (read: would 
> this be wise, or am I overlooking something)?


I'd encourage you to file this as an enhancement request against GDAL and
we will see if Howard would like to incorporate it.  I don't like that
the spatial reference would not be captured though I can see that doing
so would be quite hard.

Best regards,
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org

More information about the FWTools mailing list