On Feb 1, 2010, at 1:36 AM, Florian Lohoff wrote:

>
> Hi,
> quiete regular i have the problem that i'd like to render stuff with
> mapnik and an XML file. Now i need to change the datasource e.g. for
> switching to historic tables or something.
>
> Currently i am modifying the XML itself with regex like this:
>
> for line in i:
>       line=line.replace("%PREFIX%", "germany_" + date)
>
>
> where the Datasource is something like this:
>
>       (select way,admin_level from %PREFIX%_roads where  
> "boundary"='administrative') as admin</Parameter>
>

Perhaps you could use XML entities?

Dane


> Is there a way to change this from python - e.g. read the XML
> file and modify the datasource afterwards?
>

You could open the file in python, e.g `file =  
open('map.xml','r').read()`

Then switch out your variables using basic python string expressions.  
Or you could use one of the many great python XML templating languages  
to do the same thing.

Then once you have the xml loaded and variables placed you can pass  
the xml string to the mapnik.load_map_from_string() function.

> An alternative would be to add a layer and reference Styles in
> the XML afterwards, which would probably break the layering.
>

Or, just load the xml styles with load_map(), then contruct the  
datasources dynamically in python, but this would be more involved.

> Flo
> -- 
> Florian Lohoff                                                 [email protected]
> "Es ist ein grobes Missverständnis und eine Fehlwahrnehmung, dem Staat
> im Internet Zensur- und Überwachungsabsichten zu unterstellen."
> - - Bundesminister Dr. Wolfgang Schäuble -- 10. Juli in Berlin
> _______________________________________________
> Mapnik-users mailing list
> [email protected]
> https://lists.berlios.de/mailman/listinfo/mapnik-users

_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users

Reply via email to