4

I am trying to clip a raster using mask vector polygon layer. But clipping it causes some pixels at the edge to not get included in the output raster. I want to get all the pixels in and the ones which fall on the line to be included into the outptut file raster. I am using gdalwarp to clip the file something like: gdalwarp -q -cutline Masklayer.shp -tr 0.125 0.125 "input.tif" "output.tif" enter image description here

  • I am unsure of a specific argument for gdalwarp that does the task you want, but one potential work around could be to buffer the polygon layer by a small amount, and then use that to clip the raster. – jbukoski Jul 5 '17 at 2:02
  • Wouldn't doing that leave me with some more unwanted pixels in my output raster? – Kuljeet Keshav Jul 5 '17 at 2:04
  • Try to buffer with the exact pixel size of the resulting raster, that might work well. – pLumo Jul 5 '17 at 8:25
  • Other option would be to create the raster with the same spatial resolution as the vector (might become a huge file...) and then scale down. – pLumo Jul 5 '17 at 8:26
  • gdalwarp's -cutline is working as it should. The "problem" described here might be due to the source raster's high pixel resolution, or the target's (specified) high resolution (eg what's the map unit for -tr ?) Also - if you require fine-grain control over which "pixels" get included or excluded - PostGIS is a good choice. – Ralph Tee Sep 16 '18 at 15:34
1

Another option would be to create an empty copy of your raster, e.g. Then you can use gdal_rasterize with the ALL_TOUCHED flag to burn your polygon layer into the empty raster (see the examples on the gdal_rasterize page).

0

Another option would be to Polygonize the raster (under Raster > Conversion), use the Intersection command (Vector > Geoprocessing Tools) then Rasterize the resulting vector layer (Raster > Conversion). This would take more time, but you could get an exact cut along the mask layer.

  • Tried this. The intersection does give me the area I require, but then converting them to raster gives the same result as earlier as it leaves out many polygons which are not complete rectangles. – Kuljeet Keshav Jul 5 '17 at 19:32

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.