Thanks Dane - I will have a look at those examples. Regards
Graham. On 21 December 2010 19:00, Dane Springmeyer <[email protected]> wrote: > Graham, > > Yes Pablo's example should help. Basically Layers are an ordered list when > attached to a Map, so you can grab then via indexing. > > If you need to find a layer by name then you should loop through all layers > until you match a name. > > e.g.: > > def find_layer_by_name(m,name): > for lyr in m.layers: > if lyr.name == name: > return lyr > return None > > I've just also added a test which demonstrates the indexing functionality > and the ability to load a map, then modify the layers within: > > > http://trac.mapnik.org/browser/trunk/tests/python_tests/layer_modification_test.py > > That test was added to trunk but the basic functionality should work fine > with any version of Mapnik. > > The one catch is that datasources are validated at load time, which is why > I left out the <Datasource /> element completely in that test. The > alternative is: http://trac.mapnik.org/ticket/682 > > Dane > > > On Dec 21, 2010, at 9:23 AM, Graham Jones wrote: > > Thanks Pablo - I will have a look at your example and see if I can get it > working. > > Regards > > Graham. > > On 21 December 2010 16:47, Pablo Carreira <[email protected]>wrote: > >> Hi Graham, >> >> >What I would like to do is combine the two - have the main map >> definition in an XML file, but then tweak it using python before rendering >> (ie switching layers on and off, changing datasources >etc.). >> >> >If anyone could confirm if this is supposed to be possible it would be >> appreciated, as would any pointers to examples or documentation? >> >> >> Very interesting. >> >> I've managed to do something like that, layer definitions in XML and some >> styles in python, look at the example: >> >> Bye. >> >> >> >> import mapnik >> >> >> >> mapfile='map_definitions.xml' >> m = mapnik.Map(5600, 2400) >> mapnik.load_map(m, mapfile) >> lay=m.layers[0] #this is a layer that was created in XML >> s = mapnik.Style() >> r=mapnik.Rule() >> >> >> t = mapnik.TextSymbolizer('name', 'DejaVu Sans Book', 10, >> mapnik.Color('black')) >> t.allow_overlap=1 >> t.label_placement=mapnik.label_placement.line >> >> >> r.symbols.append(t) >> s.rules.append(r) >> m.append_style('My Style',s) >> lay.styles.append('My Style') >> bbox = mapnik.Envelope(228723,7485713,230810,7484489) >> m.zoom_to_box(bbox) >> mapnik.render_to_file(m, 'temp_teste.jpg','jpeg') >> >> >> >> _______________________________________________ >> Mapnik-users mailing list >> [email protected] >> https://lists.berlios.de/mailman/listinfo/mapnik-users >> >> > > > -- > Graham Jones > Hartlepool, UK. > > _______________________________________________ > Mapnik-users mailing list > [email protected] > https://lists.berlios.de/mailman/listinfo/mapnik-users > > > -- Graham Jones Hartlepool, UK.
_______________________________________________ Mapnik-users mailing list [email protected] https://lists.berlios.de/mailman/listinfo/mapnik-users

