def create_mapnik_datasource(self, user_id, global_id): # First create the SQL query that is a join between pollster_zip_codes and # the chart query as created by the user; then create an appropriate datasource. if global_id and re.findall('[^0-9A-Za-z-]', global_id): raise Exception("invalid global_id "+global_id) table = """SELECT * FROM %s""" % (self.get_view_name(),) if self.sqlfilter == 'USER' : table += """ WHERE "user" = %d""" % (user_id,) elif self.sqlfilter == 'PERSON': table += """ WHERE "user" = %d AND global_id = '%s'""" % (user_id, global_id) table = "(" + table + ") AS ZIP_CODES" if settings.DATABASES["default"]["ENGINE"] == "django.db.backends.sqlite3": name = settings.DATABASES["default"]["NAME"] return mapnik.SQLite(file=filename, wkb_format="spatialite", geometry_field="geometry", estimate_extent=False, table=table) if settings.DATABASES["default"]["ENGINE"] == "django.db.backends.postgresql_psycopg2": name = settings.DATABASES["default"]["NAME"] host = settings.DATABASES["default"]["HOST"] port = settings.DATABASES["default"]["PORT"] username = settings.DATABASES["default"]["USER"] password = settings.DATABASES["default"]["PASSWORD"] return mapnik.PostGIS(host=host, port=port, user=username, password=password, dbname=name, geometry_field="geometry", estimate_extent=False, table=table)
m.append_style('My Style2', s2) # Projection from PostGIS-Layer-Data lyr = mapnik2.Layer( 'Geometry from PostGIS', '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over' ) lyr2 = mapnik2.Layer( 'Geometry from PostGIS', '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over' ) # PostGIS-Connection + DB-Query lyr.datasource = mapnik2.PostGIS(host=hostname, user=db_user, password=db_pw, dbname=db_name, table=db_query) lyr2.datasource = mapnik2.PostGIS(host=hostname, user=db_user, password=db_pw, dbname=db_name, table=db_query2) # Append Style to layer lyr.styles.append('My Style') lyr2.styles.append('My Style2') ### ### END Layer 1 ###