I want to set snap raster for the function rasterize of GDAL, but I can not found. The options parameters are as the following code (C#). What is wrong?

rasterizeOptions = new string[] { "ALL_TOUCHED=TRUE", "ATTRIBUTE=" + fieldName }; //To set all touched pixels into raster pixel  

    Gdal.RasterizeLayer(myDataset, 1, bandlist, layer, IntPtr.Zero, IntPtr.Zero, 1, burnValues, rasterizeOptions, new Gdal.GDALProgressFuncDelegate(ProgressFunc), "Raster conversion");

This seems to be possible in other tools such as [ArcGIS’s Polygon to Raster] snap raster

  • Please explain what "snap raster" should do.
    – user30184
    Commented Jul 15, 2022 at 15:21
  • When I do some operations between rasters, if cells' center is not the same, Then I can assign the center of the output raster.
    – yixing
    Commented Jul 16, 2022 at 13:32

2 Answers 2


I would have a try by making an empty copy of the raster to be snapped with gdal_create https://gdal.org/programs/gdal_create.html

gdal_create -if prototype.tif output.tif

and then rasterize the vectors into this empty template file "output.tif".

  • many thanks too, I will try to finish the snap function based on your help. This is also a good idea.
    – yixing
    Commented Jul 22, 2022 at 13:34

I'm aware of two ways that raster snapping can be accomplished in QGIS:

  1. From the Raster > Projections > Warp tool. With this tool, the input layer is the layer to be adjusted (snapped). The only options that have to be set are 1) the Output file resolution in target georeferenced units, which is set to the snap raster’s pixel size and 2) the Georeferenced extents of output file to be created” drop-down, where the snap raster is selected.

You'll notice that this builds a GDAL/OGR console call, visible near the bottom of the tool. You can copy/paste this text should you wish to utilize a GDAL operation outside of QGIS.

  1. Use the Raster > Align Raster tool.

These have been previously discussed at: Specifying snap raster in QGIS?

To help people understand the snap raster concept, ESRI has a nice explanation at https://desktop.arcgis.com/en/arcmap/latest/tools/environments/how-snap-raster-environment-works.htm Since links can go stale, here's a screenshot from that web page that provides "a picture is worth a thousand words" view:

enter image description here

  • many thanks, I will try to finish the snap function based on your help.
    – yixing
    Commented Jul 22, 2022 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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