Opened 17 years ago
Closed 17 years ago
#1486 closed enhancement (fixed)
Support Python object serialization (pickle) of OGRGeometry
Reported by: | Owned by: | hobu | |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | PythonBindings | Version: | unspecified |
Severity: | minor | Keywords: | |
Cc: |
Description (last modified by )
[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
Change History (3)
comment:3 by , 17 years ago
Description: | modified (diff) |
---|---|
Priority: | highest → normal |
comment:4 by , 17 years ago
Status: | new → assigned |
---|
I don't think it would be hard to stick a copy of the spatial reference along with the geometry in the pickle... the problem is that it would be *huge*.
I've wanted to do pickles in OGR for a long time, and part of the reason I've invested some effort in PCL is to get stuff like that. I'm not convinced that pickles, even of just geometry, isn't the path on the road to hell :) OGR is kind of disjoint in that it has free-standing geometries, but not free-standing features, layers, etc. The next item on the slope is pickling of features, then layers, etc, and so on. I don't think it can be done reliably.
All that said, let's put it in the ng bindings for the few people who might try to use it. When they have trouble and find this ticket, they can't say they weren't warned :)