Ticket #1486 (closed enhancement: fixed)
Support Python object serialization (pickle) of OGRGeometry
| Reported by: | jack.riley@… | Owned by: | hobu |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | PythonBindings | Version: | unspecified |
| Severity: | minor | Keywords: | |
| Cc: |
Description (last modified by warmerdam) (diff)
[Originally posted to FWTools list February 2007, and Frank suggested that I submit as an enhancement request against GDAL]
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 the Geometry class in (my copy of) ogr.py:
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
Frank's response to my posting of this on the FWTools list included the comment: "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, Jack
