I've been using geodjango lately and am very excited about the
possibilities of the project. I'm curious about the potential/interest
for a django datasource in Mapnik. Have any mapnik users/devs given
thought to this?
Integration of Mapnik as WMS into geodjango is something that should/
will likely happen on the django side, of course. But I am
particularly interested in using Mapnik to generate static map
graphics directly through the python bindings. In this sense I figure
it would be slick to enable Mapnik to read django queryset objects
directly. How feasible would this be? Could the existing WKB reader be
used to hook directly to the geodango.wkb?
I've already managed to get mapnik working in my django projects
(using Newforms-Admin) by converting single geodjango objects to the
necessary format to send to the mapnik PostGIS datasource.
It's a hack along the lines of what is pasted below.
I'm interested in better ways.
Thanks,
Dane
# example using from django admin models and mapnik to build a map
thumbnail for a given geometry.
from mapnik import *
from django.contrib.gis import admin
from django_project.django_app.models import MyGeoAdminModel
from django_settings import DATABASE_HOST, DATABASE_USER,
DATABASE_PASSWORD, DATABASE_NAME
def get_mapnik_sql(self):
'''
Get Raw SQL for django object
'''
cols, sql, args = self._get_sql_clause()
raw_sql = "(SELECT %s %s) as django_table" % (', '.join(cols),
sql % tuple(args))
unquoted_sql = raw_sql.replace('"', '')
return unquoted_sql
#Instantiate the mapnik stuff
m = Map(60,30,"+proj=latlong +datum=WGS84")
....snip ... making map styles, rules, layers...
lyr = Layer('Django_Layer')
#Grab the django object
geodjango_object = MyGeoAdminModel.objects.filter(id=self.id)
# Turn a django object into the SQL needed for the PostGIS driver
mapnik_query = get_mapnik_sql(geodjango_object)
lyr.datasource =
PostGIS
(host
=
DATABASE_HOST
,user
=
DATABASE_USER
,password=DATABASE_PASSWORD,dbname=DATABASE_NAME,table=mapnik_query)
#Save the map to the filesystem
m.zoom_to_box(lyr.envelope())
mapname = 'static/mapnik/%s.png' % self.id
render_to_file(m,mapname,'png')
_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users