I have some super simple code that I'm using to clip raster data to US Highways. However, the clip isn't producing pixels for everywhere that the shapefile intersects the raster and I cannot figure out why this is the case. Here is the code:

gdal.Warp(input_raster_filepath, output_raster_filepath, cutlineDSName=road_buffered_filepath, cropToCutline=True)

Here is the raster and shapefile before the clip: Raster and Shapefile before the clip

And here is the raster after the clip: Raster after the clip

I was expecting for there to exist a pixel from the raster at every point along the highway but this is not the case. Can anyone explain why? Or could anyonen provide a better method for doing this?

1 Answer 1


You probably need to enable the CUTLINE_ALL_TOUCHED warp option:

CUTLINE_ALL_TOUCHED: This defaults to FALSE, but may be set to TRUE to enable ALL_TOUCHEd mode when rasterizing cutline polygons. This is useful to ensure that that all pixels overlapping the cutline polygon will be selected, not just those whose center point falls within the polygon.

  • Thank you, this worked!
    – JWB
    Jun 26, 2020 at 16:13
  • Please accept the answer as well if it solved the problem.
    – user30184
    Jun 30, 2020 at 17:43

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.