0

I'm playing around with Mapnik and trying to add a PNG image over a map created from an XML file. This is my XML file:

<Map background-color="white" minimum-version="0.7.2" srs="+init=epsg:3395">
    <Style name="population">
        <Rule><PolygonSymbolizer fill="#c7e9b4" /></Rule>
    </Style>

    <Layer name="countries" srs="+init=epsg:3395">
        <StyleName>population</StyleName>
        <Datasource>
            <Parameter name="type">shape</Parameter>
            <Parameter name="file">world_merc</Parameter>
        </Datasource>
    </Layer>
</Map>

And my code is like this:

import mapnik

m = mapnik.Map(600,400)
xml = 'population.xml'
mapnik.load_map(m, xml)

s = mapnik.Style()
rule = mapnik.Rule()
sym = mapnik.RasterSymbolizer()
rule.symbols.append(sym)
s.rules.append(rule)
m.append_style('Raster Style', s)

lyr = mapnik.Layer('GDAL Layer')
#lyr.srs = '+init=epsg:3395'
lyr.datasource = mapnik.Gdal(file='data.png', bbox=(0,0,1000,1000))
lyr.styles.append('Raster Style')
m.layers.append(lyr)

m.zoom_all()
mapnik.render_to_file(m,'map.png')

When that lyr.srs line is uncommented, the image is not shown, only the XML layer is there. When it is commented out, only a small part of the image is shown above the XML layer, the lower left corner of the image seems to be at the position of the origin of the SRS.

I just think that PNG files don't have info about where they should be, so the parameter bbox of the Gdal function seems to be good; however, it appears that that parameter doesn't have any effect in my code. The documentation is for mapnik 2.2 and my mapnik version is 3.0 so I'm not sure though.

Could someone tell me whether the parameter bbox has the same meaning as I think, and how I can control the position and size of the image displayed on the map?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.