NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

The OSM help wiki page on Mapnik states:

It can read ESRI shapefiles, PostGIS, TIFF rasters, .osm files, any GDAL or OGR supported formats, CSV files, and more.

How exactly does Mapnik integrates with PostGIS? To me saying "Mapnik can read PostGIS" is kind of like saying "Wordpress can read MySQL". Obviously Wordpress is heavily reliant on a given schema existing within that database. So what are the rules? What is Mapnik expecting to find / what must the PostGIS provide?

asked 28 Jan '15, 22:13

mapgenius323's gravatar image

accept rate: 0%

edited 28 Jan '15, 22:25

aseerel4c26's gravatar image

aseerel4c26 ♦

What problem are you trying to solve? Perhaps it might be better to provide a more specific example so that people can provide more specific answers.

Is the question that you're trying to ask actually "do I have to use PostGIS, or can I use a different database instead?"

(29 Jan '15, 08:26) SomeoneElse ♦

No, I'm not trying to ask that question. I definitely want to at least get a handle on using the PostGIS backend with Mapnik. The problem I'm trying to solve is understanding PostGIS and Mapnik integration in general.

(30 Jan '15, 07:59) mapgenius323

It means what it says. Mapnik can connect to a PostGIS database, and then read the data from that. Within your mapnik style file, you specify the schema you want (connect to this table, the geometry column is called geom/whatever). So it doesn't matter what schema you have in the database, you can tell mapnik to work with it.

permanent link

answered 29 Jan '15, 13:05

rorym's gravatar image

accept rate: 11%

OK fair. I just need some good examples of Mapnik style file talking to PostGIS. There does not seem to be any in the OSM wiki. Right now I'm in the process of pulling some packages from ppa:kakrueger/openstreetmap repo so I can check out the style files that are apparently in there. Should be what I need.

(29 Jan '15, 19:54) mapgenius323

The following styles have or produce mapnik Stylesheets which communicate with postgis / postgres databases (I have most of them up and running at my local server). Maybe this is what you want to find actually:

OSM: German OSM: OSMBright: OSMNight: SwissStyle: Cassini: Blossom:

(29 Jan '15, 20:38) nordie69

@nordie69 Great links thx. The first one is good for me. I didn't realise OSM now uses CartoCSS for styling (whatever that is). Also lead to which appears to be the old XML style sheet (+4000 lines, holy crap!). This XML also declares a bunch of Layers towards the end.

(30 Jan '15, 08:23) mapgenius323

the current style is written in CartoCSS (which is a 'nicer' way to write mapnik style files). It's then converted into mapnik XML with the carto command line tool. (see the docs on installing it )

(30 Jan '15, 09:04) rorym

@mapgenius323: "I didn't realise OSM now uses CartoCSS" – you really should just read the Mapnik wiki page. It is mentioned there (prominently in the intro section). You may find other interesting bits on that page.

(30 Jan '15, 13:53) aseerel4c26 ♦

@aseerel4c26 I did read that page. I missed that though. I disagree that that is prominent. I find the entire OSM wiki a muddle, but that is my personal opinion, and I am still grateful for its existence of course.

(30 Jan '15, 21:53) mapgenius323
showing 5 of 6 show 1 more comments

Examining OSM's Mapnik style sheet is the best way to get a feeling for how Mapnik integrates with a Postgres/PostGIS database. This is available at Note that OSM now specifies its style in CartoCSS, but these CartoCSS style sheets are still compiled into Mapnik XML style sheets. Also see for more info on CartoCSS.

Basically, Mapnik has an abstraction layer, with drivers for each type of data source ("layer"). These drivers read geometric data in some specific external format in to some internal format used by Mapnik. This internal format geometric data eventually finds its way to symbolizers and onto a canvas via way of "styles", which get attached to each layer. The PostGIS driver requires you to specify a SQL query that returns a table of data. That table must contain a column called "way" of PostGIS type "geometry". The table may contain arbitrary other columns. These other columns can be used to support rendering (how they can be used I don't know yet). But in most cases all that is needed for a symbolizer to render something is the way column. Layers also need a database connection configuration. The following link shows a complete and working, but very basic Mapnik style sheet with a PostGIS layer -

P.S. Thanks for help from commenters above. Please feel free to add to or expand on this answer.

permanent link

answered 31 Jan '15, 11:10

mapgenius323's gravatar image

accept rate: 0%

What about the section Data Sources → PostGIS? Essentially, Mapnik does not care about your database schema as long as you can provide suitable SQL queries that will extract the data for each layer you want to define. The query you provide will be augmented with a bounding box condition by Mapnik, and other than a geometry it only needs to return those column you expect to use in the styling rules that you have written.

permanent link

answered 28 Jan '15, 22:31

aseerel4c26's gravatar image

aseerel4c26 ♦
accept rate: 18%

edited 28 Jan '15, 22:58

Frederik%20Ramm's gravatar image

Frederik Ramm ♦

So the only advantage of having the data in PostGIS is speed and some convenience GIS function? I could essentially have any SQL server and write arbitrary queries in a Mapnik style file?

(29 Jan '15, 06:39) mapgenius323

"... and other than a geometry ..." Could you please elaborate on this. I think this is what I'm getting at.

(29 Jan '15, 06:41) mapgenius323

"What about the section Data Sources → PostGIS?". I did not find that very helpful.

(29 Jan '15, 06:43) mapgenius323

@mapgenius323: it is not "very" helpful, yes. But more than the cited part of the intro.

(29 Jan '15, 12:50) aseerel4c26 ♦

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 28 Jan '15, 22:13

question was seen: 9,744 times

last updated: 31 Jan '15, 11:10

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum