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"

  • 2
    you will need to use a different driver that supports update access, such as GTiff (.tif) – Mike T Mar 12 '15 at 9:32
  • But what if the input and output file should be in png not in GTiff(.tif)? Is there any other option? Or just set another output path so that the files will not need any update. – lovelyvm Mar 13 '15 at 1:19
  • Convert the .png to .tif for gdal_rasterize, then back to .png at the end. You can use gdal_translate for this purpose. – Mike T Mar 16 '15 at 0:26

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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