3

I'm currently trying to cutline crop a tif with a shapefile and no matter what I do I have pixel either overhanging the cutline or being cropped too early.

So here is an example picture of what is happening when I use gdalwarp: enter image description here

When I use arcpy to crop I get this result:

enter image description here

The code I am currently using with gdal warp is:

 gdalwarp.exe -ot "float32" -s_srs "+proj=longlat +ellps=WGS84 +datum=WGS84 
 +no_defs " -t_srs "+proj=utm
 +zone=48 +ellps=WGS84 +datum=WGS84 +units=m +no_defs "-of "GTiFF" -cutline 
 mask.shp -crop_to_cutline infile.asc outfile.tif -wm 5000 -tap -tr 100 100 -overwrite

I am quite keen to use gdal if possible to do this cropping as it is considerably faster


I have been asked to provide gdalinfo info, see below. This is from the gdal code: enter image description here

This is from the arcpy code: enter image description here

SOLUTION was found in comments.

Exactly what I wanted:

enter image description here

My new problem to ponder next is: [enter image description here]

  • 1
    What is the output from a gdalinfo on the arcpy result? – Mikkel Lydholm Rasmussen Feb 12 '18 at 14:02
  • 1
    And is the resolution of the input data also 100m? – Mikkel Lydholm Rasmussen Feb 12 '18 at 14:42
  • 1
    The resolution of your arcpy image seems to be much higher along the cutline. Or is the cutline covering part of pixels? Are the visible blocks in the raster 100 by 100 meters in size? – user30184 Feb 12 '18 at 14:53
  • 2
    You could try setting -wo CUTLINE_ALL_TOUCHED=TRUE, so that all pixels overlapping the cutline polygon will be selected, not just those whose center point falls within the polygon. see gdal.org/… – dr_times Feb 12 '18 at 15:22
  • 1
    Please consider writing the solution as an answer, and accepting it. This will mark the question as answered for future reference. – Roberto Ribeiro Feb 12 '18 at 16:46
3

The solutiuon was to add the option: -wo CUTLINE_ALL_TOUCHED=TRUE

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.