I'm trying to use gdal_rasterize to convert a polygon shapefile into a raster, where the value comes from the 'COVTYPE' attribute. I try calling gdal rasterize like so (I'm calling from within a python script so I have to call os.system):

os.system("gdal_rasterize -a COVTYPE -l %s -a_nodata 999 -a_srs EPSG:102001 -t 30 30 %s %s" % (bname, inshp, outrast))

Where bname is the basename of the shapefile (aka the layer name), inshp is 'inpath/bname.shp' and outrast is 'outpath/bname.tif'.

And get the error : "ERROR 1: Attempt to create 0x0 dataset is illegal, sizes must be larger than zero. Cannot create outpath/bname.tif"

It was my understanding that with gdal>1.8 (I'm running gdal 1.9.2), gdal_rasterize could create a new raster file as long as -tr (target resolution) or -ts (target size) is set (see http://www.gdal.org/gdal_rasterize.html). I'm setting the target resolution, so I don't see why it thinks I'm trying to create a 0x0 raster. Additionally, documentation says that if the target extent isn't set, it'll take the extent of the vector layer, which is want I want.

I've tried calling gdal_rasterize outside of python and get the same error. I also tried rearranging some of the keywords and taking away the a_srs keyword thinking it may be causing problems (a_srs overrides the default projection for the output file), but still to no avail.

Does anyone have an inkling as to what's going on?

  • Tell us more about the source file using ogrinfo -so inpath bname, and update your question.
    – Mike T
    Dec 17, 2014 at 21:47
  • Luke- that wasn't actually in my script, I just mistyped when writing the question. I'm about to post the answer. thanks.
    – user20408
    Dec 18, 2014 at 16:13
  • Mike T- you're on the right track. I guess gdal didn't recognize the projection the shapefile was in because after reprojecting first then rasterizing, it worked.
    – user20408
    Dec 18, 2014 at 16:15

2 Answers 2


So after using gdal_translate to reproject the shapefile first, then using that as the input for gdal_rasterize, everything worked. I'm assuming that gdal didn't recognize the shapefile's projection (it wasn't anything I'd seen either) and that just caused the whole thing to fail. It makes sense, but I wish the error raised would've pointed to that, and I could have saved a lot of time. So, the final solution is:

os.system("ogr2ogr -t_srs EPSG:102001 %s %s" % (rpshp, inshp)) # output then input
os.system("gdal_rasterize -a COVTYPE -l %s -a_nodata 999 -tr 30 30 %s %s" % (rbname, rpout, outrast)) # layername (basename of reprojected shp), input then output
  • Luke, ogr2ogr can reproject, -t_srs
    – user10353
    Dec 19, 2014 at 18:26

The problem looks to be of vector feature size. Total vector features in input file may be covering area less than 1x1 pixel square i.e. less than -tr 30 30 , 30x30 units area.

So solution can be

1) reduce resolution further (say -tr 1 1) matching with extents of input vector file


2) Workaround - place one more vector feature in input file so that combined extent of input vector file is more than 1 square pixel

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.