This question already has an answer here:

I want to convert a .shp to .tif. So I find the tool gdal_rasterize may help. But when I input the file it always meet this error:

pointer hDs is NULL in GDAL GetProjectionRef


I have tried different versions of GDAL(1.11.0 and 2.1.0),same error. The test data is from http://qgis.org/downloads/data/qgis_sample_data.zip

1)Is this wrong because of the data?or the wrong syntax?

2)What is the correct syntax for using gdal_rasterize()?

3)Is there a better way to convert shp to png(or tif)?coding by myself is ok but I use Java.

marked as duplicate by user2856, nmtoken, Andre Silva, artwork21, whuber Dec 24 '16 at 15:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • gdal_rasterize -burn 255 -burn 0 -burn 0 -ts 640 480 input.shp output.tif - works for me. If I added bands (-b 1 -b 2 -b 3), I get error: ERROR 6: -b option cannot be used when creating a GDAL dataset. – Dmitry Baryshnikov Sep 28 '16 at 9:02
  • I think it's a different situation... – user83388 Oct 9 '16 at 13:57

You will get that error if you are trying to rasterize into an output raster that doesn't exist.

C:\Temp>dir /b test.tif
File Not Found

C:\Temp>gdal_rasterize -b 1 -burn 255 test.shp test.tif
ERROR 10: Pointer 'hDS' is NULL in 'GDALGetProjectionRef'.

Warning 1: The input vector layer has a SRS, but the output raster dataset SRS is unknown.
Ensure output raster dataset has the same SRS, otherwise results might be incorrect.

If you want GDAL to create your output raster for you, you need to specify the output extent and pixel size.

Something like:

ogrinfo -so test.shp test

INFO: Open of `test.shp'
      using driver `ESRI Shapefile' successful.

Layer name: test
Geometry: Polygon
Feature Count: 3
Extent: (-107.098004, 41.168652) - (-104.171267, 44.190567)
Layer SRS WKT:
OID_: Integer (9.0)

gdal_rasterize -te -107.2, 41.0, -104.1, 44.2 -tr 0.01 0.01 -burn 255 test.shp test.tif

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