2

I'm trying to convert a multipolygon vector layer to a raster using the GDAL tool gdal_rasterize. The command I am using is:

gdal_rasterize -b 1 -burn -9999 PG:"dbname=db password=password" \
    auckland auckland.png

However, it seems my specification of the source for the postgis layer is incorrect as I get an

ERROR 4: 'auckland.png' does not exist in the file system,
and is not recognised as a supported dataset name.` 

So how do I successfully connect to postgres and export a vector as a tif? Is it possible?

Numerous other attempts have included:

gdal_rasterize -b 1 -i -burn -9999 PG:"dbname=db password=" -l \
    auckland auckland.png

gdal_rasterize -b 1 -i -burn -9999 -l auckland PG:"dbname=db \
    password=password" auckland.png

And this one from Roger's Rants:

gdal_rasterize -b 1 -i -burn -9999 PG:'host=localhost dbname='unep'' \
    -sql "SELECT ST_buffer(the_geom, .12) from coastlines where name='Poland'" \
    Poland_elev.tif

When I use ogr2ogr to export the layer out of postgres as a shapefile, and then gdal_rasterize to convert to a .tif file it all works smoothly.

Using GDAL 1.11.2 version on Ubuntu 15.10.

Still no love with either:

gdal_rasterize -b 1 -burn -9999 PG:"dbname=db password=pwd" \
    -l auckland auckland.tif

or:

gdal_rasterize -b 1 -burn -9999 -l auckland PG:"dbname=db \
    password=pwd" auckland.tif
Phil Donovan
  • 980
  • 11
  • 20
  • How does your ogr2ogr command look like, especially the PG: part? – user30184 Mar 30 '16 at 08:54
  • Test the PostGIS connection part with ogr2ogr. When it is right ogr2ogr will list the layers. Use the connection string as datasource for gdal_rasterize and use the name of the desired layer as a value for -l. I suppose that your output image exists but do read the manual, png will not work The GDAL supported output file. Must support update mode access. – user30184 Mar 30 '16 at 09:30
  • ogr2ogr -f "ESRI Shapefile" auckland.shp PG:"dbname=db password=password" auckland.

    In regards to png, I have been using tif but switched to png to test whether that was issue. The error message never changed and I never switched back to tif.

    – Phil Donovan Mar 30 '16 at 19:25
  • 1
    This command works for me on Windows with GDAL 2.1-dev. Data are multipolygons from the demo data of GeoServer. gdal_rasterize -i -burn -9999 PG:"dbname='my_db' host='localhost' port='5432' user='my_user' password='my_password'" -l states -a_srs epsg:4326 -tr 0.1 0.1 output.tif Output.tif did not exist which lead to an error with -b 1 which you used so I left it out. – user30184 Mar 30 '16 at 21:18

1 Answers1

2

To create a new raster with gdal_rasterize, either the -tr or -ts option must be used, and the -b option cannot be used.

E.g.

gdal_rasterize -burn -9999 -tr 0.001 0.001 PG:"..." -l auckland auckland.tif
Mike T
  • 42,095
  • 10
  • 126
  • 187