Opened 18 years ago

Closed 17 years ago

Last modified 17 years ago

#4322 closed (fixed)

[gis] Lazy-instantiated geometry objects

Reported by: robert.coup@… 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)

gis_lazy_geometries.diff (7.2 KB ) - added by robert.coup@… 18 years ago.
gis_lazy_geometries.2.diff (7.1 KB ) - added by robert.coup@… 18 years ago.
2nd update
gis_lazy_geometries.2.2.diff (7.2 KB ) - added by robert.coup@… 18 years ago.
2nd update

Download all attachments as: .zip

Change History (10)

by robert.coup@…, 18 years ago

Attachment: gis_lazy_geometries.diff added

comment:1 by robert.coup@…, 18 years ago

Needs documentation: set
Needs tests: set
Patch needs improvement: set

hmm, there is extra code in there to allow creation of NULL fields. That should probably be a separate pre-patch.

comment:2 by Jeremy Dunck, 18 years ago

Component: Contrib appsGIS
Owner: changed from Adrian Holovaty to Jeremy Dunck

by robert.coup@…, 18 years ago

Attachment: gis_lazy_geometries.2.diff added

2nd update

by robert.coup@…, 18 years ago

2nd update

comment:3 by robert.coup@…, 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 jbronn, 17 years ago

Cc: jbronn@… added
Owner: changed from Jeremy Dunck to jbronn
Status: newassigned

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 jbronn, 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 jbronn, 17 years ago

Resolution: fixed
Status: assignedclosed
Triage Stage: UnreviewedAccepted

Added support in #5657. Great job Robert, this is truly an excellent enhancement -- sorry for the delay.

comment:7 by jbronn, 17 years ago

err, I meant r5657.

Note: See TracTickets for help on using tickets.
Back to Top