1

I would like to clip some tiff files using cutline from kml file.

enter image description here

.\gdalwarp.exe -of GTiff -co COMPRESS=LZW -cutline boundingbox.kml source.tif result.tif

It works quite well but as a result I have files with the same size as before.

Is it possible to adjust result image size to the result content?

Here I would like to get rid of that black border.

enter image description here

Edit: When I add -crop_to_cutline parameter then result is even worse: enter image description here

1

Once you've define you cutline you have to tell it to crop the image to the cutline like so:

gdal.Warp(Outraster, Inraster, format = 'GTiff', cutlineDSName = polygon, cropToCutline = True
  • Well the result is even worse because output image has size of full clipper. Please take a look at my question which I edited. – Witos Feb 22 at 10:33
  • I believe if you define an Alpha band for your raster you should be good using -dstalpha: – B-C B. Feb 22 at 19:10
  • Yes it looks better but size is the same, I thought that maybe size (dimensions) can be reduced as well to fit only area with image (that small corner) :) – Witos Feb 22 at 21:38
  • maybe define -srcalpha aswell... – B-C B. Feb 25 at 15:41
  • if that doesn't work you could clip your "clipper" polygon to the extent of your raster file prior to doing this clip – B-C B. Feb 25 at 18:01

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.