id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 4322,[gis] Lazy-instantiated geometry objects,robert.coup@…,jbronn,"Ok, as discussed on the [http://groups.google.com/group/django-developers/browse_thread/thread/93fc74069e10aa17 dev list] (earlier discussions [http://groups.google.com/group/django-developers/browse_thread/thread/b15d58bf96bc2efc 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.",,closed,GIS,dev,,fixed,gis,gulopine@… jdunck@… jbronn@…,Accepted,1,1,1,1,0,0