I have a geotiff, whose gdalinfo gives the following information about the georeferencing:

WGS 84 / UTM zone 32N 

Now, I apply a simple gdalwarp for testing purposes:

gdalwarp -of GTiff -cutline subset.geojson InputImage.tif OutputImage.tif

The geojson subset is exactly the size of the geotiff, as I have extracted the corresponding subset before and the InputImage.tif already results from that extraction. Only thing I need to mention is that the .geojson is given in Lat-Long coordinates.

The output GeoTiff gives exactly the same gdalinfo georeferencing information!

The problem, however, now is that this operation, which actually should not do anything, changes the image: It basically slightly rotates the scene content and adds noData values around it to make for a rectangular image matrix again. Why is that? Actually, this is pretty annoying since my goal is to create subset images without any noData frames for further mathematical image processing operations. Can this be avoided somehow? In the end the task I am aiming to achieve is to extract subsets from the 10m bands of Sentinel-2 images and to store them as RGB geotiffs.

  • Could you add the cutline as WKT or eve GeoJSON into the question? – user30184 Sep 20 '17 at 17:30
  • 4
    The corners of an image in UTM will not have a rectangular extent in lat/lon unless the image is symmetric around the central meridian. I think you should double-check the subset.geojson data and, if possible, create it in UTM instead. – mkennedy Sep 20 '17 at 18:24
  • 1
    It might help if you work entirely inside the same CRS, and maybe densify the cutline geometry. – AndreJ Sep 21 '17 at 15:55

If you only want to get a subset, you might want to use gdal_translate with -srcwin parameter instead of gdalwarp.

From gdal_translate documentation:

-srcwin xoff yoff xsize ysize:
    Selects a subwindow from the source image for copying based on pixel/line location.

Using -projwin would work as well, but you'd have to be careful to perform the coordinate calculations correctly in the image's UTM CRS.

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.