#4322 closed (fixed)
[gis] Lazy-instantiated geometry objects
Reported by: | Owned by: | jbronn | |
---|---|---|---|
Component: | GIS | Version: | dev |
Severity: | Keywords: | gis | |
Cc: | gulopine@…, jdunck@…, jbronn@…, | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | yes | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Ok, as discussed on the dev list (earlier discussions here), I've created a patch for lazy-instantiated geometries.
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.
Attachments (3)
Change History (10)
by , 18 years ago
Attachment: | gis_lazy_geometries.diff added |
---|
comment:1 by , 18 years ago
Needs documentation: | set |
---|---|
Needs tests: | set |
Patch needs improvement: | set |
comment:2 by , 18 years ago
Component: | Contrib apps → GIS |
---|---|
Owner: | changed from | to
comment:3 by , 18 years ago
gis_lazy_geometries.2.2.diff fixes a bunch of pretty serious issues resulting from the number of different ways i attempted to get this working cleanly. Thanks Gulopine for pointing out the obvious things (like that it wasn't lazy :P). SRIDs should also now be handled consistently (I found an error in there under some uses).
comment:4 by , 18 years ago
Cc: | added |
---|---|
Owner: | changed from | to
Status: | new → assigned |
NULL geometry support added in r5448, combining those parts of Robert's patch with the latest updates (i.e. it was redundant to pass the field around as a parameter). Still reviewing lazy-instantiation components.
comment:5 by , 17 years ago
Cc: | gulopine@gamemusic.org, jdunck@gmail.com, jbronn@gmail.com → gulopine@gamemusic.org, jdunck@gmail.com, jbronn@gmail.com, |
---|
Writability enhancement to GEOS geometries added in r5637, as requested in IRC discussion. Will move forward with integrating lazy-geom support using GEOS geometries and Robert's patch.
comment:6 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Triage Stage: | Unreviewed → Accepted |
Added support in #5657. Great job Robert, this is truly an excellent enhancement -- sorry for the delay.
hmm, there is extra code in there to allow creation of NULL fields. That should probably be a separate pre-patch.