[gis] Lazy-instantiated geometry objects
|Reported by:||robert.coup@…||Owned by:||jbronn|
|Cc:||gulopine@…, jdunck@…, jbronn@…,||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||yes||Patch needs improvement:||yes|
The idea is to use GEOSGeometry objects as the standard representation, but only instantiate it when someone actually reads the geometry value. The patch uses a python descriptor applied to the model class with a setter and a getter.
- The getter checks whether the stored value is a GEOSGeometry (or None), otherwise it tries to create one via the setter.
- The setter (if the new value isn't None) first checks whether its a GEOSGeometry. If so, it sets the internal value. Otherwise it tries to convert it first as hex, then as wkt if it gets an exception. Logic is that the DB returns hex values and reading is probably more likely to happen than writing.
Because both the setter and getter are completely transparent to the rest of Django, it makes all the get_GEOM_xxx redundant, because you can now do model.my_geometry_field.area, etc.
This is a first stab and I'd appreciate comments.
Change History (10)
comment:1 Changed 9 years ago by robert.coup@…
- Needs documentation set
- Needs tests set
- Patch needs improvement set
comment:2 Changed 9 years ago by jdunck
- Component changed from Contrib apps to GIS
- Owner changed from adrian to jdunck
comment:4 Changed 9 years ago by jbronn
- Cc jbronn@… added
- Owner changed from jdunck to jbronn
- Status changed from new to assigned
comment:5 Changed 9 years ago by jbronn
- Cc changed from firstname.lastname@example.org, email@example.com, firstname.lastname@example.org to email@example.com, firstname.lastname@example.org, email@example.com,
comment:6 Changed 9 years ago by jbronn
- Resolution set to fixed
- Status changed from assigned to closed
- Triage Stage changed from Unreviewed to Accepted