Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to manage raster files from PostGIS, which to be rendered using Mapnik. I used raster2pgsql to load those GeoTIFF images to PostGIS, and I think the loading process turned out OK. The problem is to render from Mapnik XML using the PostGIS datasource: the rasters rendered out blank.. The raster files rendered perfectly with Mapnik XML using GDAL datasource, so I suspect my PostGIS raster configuration is at fault here.. Is there any documentation out there that resembles what I am trying to do?

Below is a snippet of my XML file to be used by Mapnik:

            <Parameter name="type">postgis</Parameter>
            <Parameter name="user">postgres</Parameter>
            <Parameter name="dbname">gis</Parameter>
            <Parameter name="geometry_field">rast</Parameter>
            <Parameter name="estimate_extent">false</Parameter>
            <Parameter name="table">staging.hillshade</Parameter>
            <Parameter name="extent">101,3,103,4</Parameter>            

I appreciate any help, thanks!

share|improve this question
Updated my answer. Looks like it's currently not supported. –  R.K. Sep 19 '12 at 7:05
I guess you're right. Have to resort to GDAL datasource for now.. Thanks @R.K. I'll choose yours as the answer. –  Haziq Sep 19 '12 at 8:16
You're welcome. Will revisit this thread to update the answer once pg_raster support comes out :) –  R.K. Sep 19 '12 at 8:21

2 Answers 2

up vote 2 down vote accepted

For those who will stumble on this question like me..

It appears that the plugin has been generated (https://github.com/strk/mapnik/tree/2.3.x-pgraster) and has been merged in official Mapnik Repo.

The branch is 2.3.x (https://github.com/mapnik/mapnik/tree/2.3.x)

Now you can build Mapnik from the branch and use PGRaster plugin to use Raster data from Postgis. The xml configuration could be as follows,

> <Layer name="MS-GIS" status="on" srs="+proj=utm +zone=18 +datum=WGS84
> +units=m +no_defs">
>     <StyleName>raster</StyleName>
>     <Datasource>
>       <Parameter name="type">**pgraster**</Parameter>
>       <Parameter name="table">ms_test</Parameter>
>       <Parameter name="**raster_field**">rast</Parameter>
>       <Parameter name="dbname">gis</Parameter>
>       <Parameter name="estimate_extent">false</Parameter>
>       <Parameter name="extent">-20037508,-19929239,20037508,19929239</Parameter>
>     </Datasource> </Layer>
share|improve this answer


I saw this discussion on Tilemill. The guy there is trying to use a raster from PostGIS as a data source. Tilemill uses Mapnik to render the tiles. I will quote Dane ( Tilemill support staff):

Hi Craig,

The PostGIS support in TileMill is (currently) only designed to be vector based. The raster storage in PostGIS is a very new feature of PostGIS - we may support it in the future but not at this point.

Raster support in TileMill is all through Mapnik's GDAL plugin. It may be possible to setup up Mapnik and GDAL to read rasters out of PostGIS, but I've not personally tried this yet. In TileMill the assumption is all rasters are simple a file on the filesystem at this point.

There is also this discussion from the Mapnik forum. This one is a response to the same question that you are asking right now:

I've never seen this done. Does GDAL support postgis raster yet? I know pg_raster uses GDAL internally, so I figure it should.

We plan to add a new mapnik plugin eventually to read directly from pg_raster.


That one's dated August 23, 2012. Chances are, things haven't changed much since then. You might have to use use the GeoTIFFS and GDAL for now. Hopefully they'll release the pg_raster support for Mapnik soon.

Found this sample snippet on the Mapnik wiki.

      <Parameter name="type">postgis</Parameter>
      <Parameter name="host">localhost</Parameter>
      <Parameter name="dbname">geodjango_geographic_admin</Parameter>
      <Parameter name="user">postgres</Parameter>      
      <Parameter name="password"></Parameter>
      <Parameter name="table">(select ST_Buffer(ST_Centroid(geometry),2) as geometry, name  from world_worldborders) as world</Parameter>
      <Parameter name="estimate_extent">false</Parameter>
      <Parameter name="extent">-180,-90,180,89.99</Parameter>

I guess you're missing the user and password parameters. Without those, Mapnik can't connect to the PostGIS database. Therefore, nothing is rendered.

The Mapnik wiki page on PostGIS might be the documentation you're looking for. I hope that helps.

share|improve this answer
I do include the user parameter, and it's postgres. I usually enter my password manually, as I don't like to show them in my XML files. I do the same thing with vector geometries with PostGIS, and they always rendered out fine.. But I did test out your theory: I included the password parameter for the PostGIS raster; but it turned out the same, nothing is rendered. Thanks for trying anyway.. –  Haziq Sep 19 '12 at 6:15
Oh... you might find the answer in the linked docs btw. –  R.K. Sep 19 '12 at 6:43
Here's the tracking bug for mapnik: github.com/mapnik/mapnik/issues/1660 –  gravitystorm Jan 24 at 11:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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