> Coercion of the type you describe is not required for any field
> currently supported. I would be hesitant to include coercion as a core
> part of the framework unless there is a generic need to coerce
> database values into Python values in some way other than that
> performed by the database backend.

The GIS branch (GeoDjango) is interested in type coercion.
Specifically, PostGIS returns geometries as hex strings to the client
-- it would be preferable to have this come into the model as either a
different type of string like WKT ("POLYGON ( .. )"), KML
("<Polygon>...</Polygon>") or as a GEOSGeometry() object.  For
example, say we have a 'ZipCode' model with a PolygonField ('poly'):

from django.contrib.gis.db import models

class ZipCode(models.Model, models.GeoMixin):
   code = models.IntegerField()
   poly = models.PolygonField()
   objects = models.GeoManager()

As it stands right now, to get the centroid of a polygon you'd have to
do the following:

z = ZipCode.objects.get(code=77002)
centroid = z.get_poly_geos().centroid

Instead, with type coercion, it could be:

z = ZipCode.objects.get(code=77002)
centroid = z.poly.centroid

The latter seems more intuitive to me.  Further, it would eliminate
the need for the 'mixin' class completely, since those routines are
for casting the hex as a geometry object and pulling out the needed
value (e.g. get_GEOM_wkt, get_GEOM_area, etc.).  While getting the KML
or WKT can be obtained from PostGIS through an extra SELECT parameter,
getting GEOSGeometry() python objects in the QuerySet would require
some sort of type coercion.

In summary, use cases outside of Gulopine's problem would benefit from
a method to perform type coercion.  I'm open to suggestions if there's
a better way to do this...

Regards,
-Justin Bronn


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to