Code

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#4322 closed (fixed)

[gis] Lazy-instantiated geometry objects

Reported by: robert.coup@… Owned by: jbronn
Component: GIS Version: master
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: UI/UX:

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@… 7 years ago.
gis_lazy_geometries.2.diff (7.1 KB) - added by robert.coup@… 7 years ago.
2nd update
gis_lazy_geometries.2.2.diff (7.2 KB) - added by robert.coup@… 7 years ago.
2nd update

Download all attachments as: .zip

Change History (10)

Changed 7 years ago by robert.coup@…

comment:1 Changed 7 years ago by robert.coup@…

  • 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 Changed 7 years ago by jdunck

  • Component changed from Contrib apps to GIS
  • Owner changed from adrian to jdunck

Changed 7 years ago by robert.coup@…

2nd update

Changed 7 years ago by robert.coup@…

2nd update

comment:3 Changed 7 years ago by robert.coup@…

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 Changed 7 years ago by jbronn

  • Cc jbronn@… added
  • Owner changed from jdunck to jbronn
  • Status changed from new to 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 Changed 7 years ago by jbronn

  • Cc changed from gulopine@gamemusic.org, jdunck@gmail.com, jbronn@gmail.com to 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 Changed 7 years ago by jbronn

  • Resolution set to fixed
  • Status changed from assigned to closed
  • Triage Stage changed from Unreviewed to Accepted

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

comment:7 Changed 7 years ago by jbronn

err, I meant r5657.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.