[GIS] Burning shapefile geometry to raster in PNG format with gdal_rasterize

gdaloverlaypngrastershapefile

I was trying to overlay a shapefile to some raster images from a directory using gdal_rasterize. But then encountered this error:

ERROR 6: The PNG driver does not support update access to existing datasets.

input_path has the raster images and the shp_path has the shapefile. Any ideas?

@echo off

set "inpath=C:\path\to\input\"
set "shppath=C:\path\to\shape\file\"


cd /d "%inpath%"

for %%a in (*.png) do (
   set "fileName=%%a"
   echo Overlaying the shape file . . .
   FORFILES /m %%a /C "cmd /c gdal_rasterize -b 1 -b 2 -b 3 -burn 0 -burn 0 -burn 0 %shppath%\shpfile.shp %in_path%\@fname.png"

)

Best Answer

The error message means you can't overwrite (update) an existing raster file of format .png with gdal_rasterize, which is what the tool does by default when the raster file already exists. See the relevant excerpt in gdal_rasterize description:

... . The target raster will be overwritten if it already exists ... .

The dst_filename parameter states that the output file must support update mode access which the error message is saying .png does not.

The work around is what @Mike T commented, use gdal_translate to convert your rasters to .tif, and then, use the .tif files together with parameter -of with gdal_rasterize to output to a .png format.

Related Question