7

There is a function in R (trim) which removes the NODATA situated in the outer rim of a raster (entire external row or column made of nodata). It is realy simple but quite slow. I am looking for a similar function or algorithm in gdal to do that. Any idea?

1 Answer 1

3

This sounds like the equivalent of GIMP's "zealous crop"

This is doable with the -cutline option in gdal_translate, but then you need to create the vector representing the valid raster data extent yourself.

Postgres has the ST_MinConvexHull, taking the ST_Envelope of that would be equivalent to what you described. Sounds a bit like overkill, though.

An easier way is with SAGA's crop to data raster method, which is available via processing. That does both steps in one (and can also do multiple rasters in one go)

2
  • I like the SAGA way, I'll use that as it seems easier then finding the extent of my valid raster to put into -cutline. Thanks
    – Bastien
    Commented Jul 11, 2017 at 17:26
  • Here's a gdal script that will trim so long as entire image can fit in memory - gis.stackexchange.com/a/149511/108 Commented Nov 19, 2018 at 21:44

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.