I was in a similar situation a few months ago. The GeoDjango branch api is really handy and I was hoping to use it on some models that were sitting in a 0.96 release. We definitely couldn't go with the unstable branch for our production environment so I ended up just writing a few custom sql queries in my models to set the geometry properties on textfields instead. One of my methods triggered by the save method goes something like this:
def set_geom_properties(self): """ triggered by save method we set some geom properties that we don't want to calculate everytime from postgis """ if self.polygon: center = ''#get centroid of area cursor = connection.cursor() geom_q = """ select geometryfromtext('POLYGON((%s))',4269); """ % (self.polygon) cursor.execute(geom_q) geom = cursor.fetchone()[0] self.geom = geom centroid_q = """ select x(centroid(transform(GeomFromEWKT('%s'), 4269))) as longitude, y(centroid(transform(GeomFromEWKT('%s'), 4269))) as latitude """ % (geom,geom) cursor.execute(centroid_q) lon, lat = cursor.fetchone() self.centroid = "%f, %f" % (lat,lon) When GeoDjango makes it into a stable release I will definitely use it and just modify my code a little bit. Its also nice to know how to setup your own geometry columns in postgis and do the queries. -Matt On 11/5/07, Hancock, David (DHANCOCK) <[EMAIL PROTECTED]> wrote: > > > We're using the Django trunk (r5988), but are about to dive into adding some > PostGIS geometry columns to a few of our models. It appears that GeoDjango > is its own branch--has anyone got advice about whether we can use it with a > more recent checkout than it branched from? > > The GeoDjango additions look quite easy to use, a plus for our organization > that's just getting started with GIS. > > If the trunk and GeoDjango AREN'T currently compatible, would it be possible > for us to add geometry columns AFTER a syncdb creates the "standard" model > tables? Would the automatic admin still work in such a situation? > > Thanks in advance for any advice you've got. Django is becoming our tool of > choice for data that needs to have an editing interface for internal use and > be queryable from our other applications and website. > > Cheers! > -- > David Hancock | [EMAIL PROTECTED] > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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-users?hl=en -~----------~----~----~----~------~----~------~--~---