I have installed the latest Mapnik renderer following the information on their website and exported a .pbf file to a local PostGIS DB using this command:

osm2pgsql --style ../openstreetmap-carto/openstreetmap-carto.style --create --database gis -U maps -W -H bucharest.osm.pbf

After this I generated a XML style sheet using carto -a "3.0.0" ../openstreetmap-carto/project.mml > mapnik.xml

Now I would like to use this mapnik.xml in a Python script to render a part of the exported map from PostGIS as a test.

#!/usr/bin/env python

from mapnik import *

mapfile = 'mapnik.xml'
map_output = 'mymap33.png'

m = Map(2048, 2048)
load_map(m, mapfile)
bbox=(Box2d( 26.08901,44.420234,26.125488,44.435067))

render_to_file(m, map_output)

The problem is that the mapnik.xml has no information about my PostGIS DB (I looked in the file and I saw a lot of queries in element but no host name, user name or password). How do I add more info about my PostGIS DB to this style sheet?

  • Check out the docs at github.com/mapnik/mapnik/wiki/PostGIS. Near the bottom there's an example of PostGIS config in XML. Commented Jan 19, 2017 at 22:53
  • Yep ... I've seen this example but the xml file generated by carto has over 35000 lines and adding information about my DB to it wont be so productive :) Commented Jan 20, 2017 at 8:58
  • 1
    I guess I'm confused then. If adding information about your DB won't be productive, why are you asking to "add more info about my PostGIS DB"? How many layers do you have? Commented Jan 20, 2017 at 19:09
  • You can provide the host name, user name and database name through the environment variables PGHOST, PGUSER, and PGDATABASE
    – Leon
    Commented Sep 7, 2018 at 6:30

1 Answer 1


You should edit project.mml like below before generating mapnik.xml:

  osm2pgsql: &osm2pgsql
    type: "postgis"
    dbname: "gis"
    host: "localhost"
    user: "username"
    password: "password"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.