I would like to be able to read a part of a TIFF file as a numpy array (using read as array(xoff, yoff, xsize, ysize) and be able to export it again to TIFF file, having this subset its correct coordinates. I was thinking obtaining the Geotransform from the original file, and adding/substracting from its coordinates, the offsets multiplied by the pixel size. I think that would give me the correct Geotransform to apply it when exporting. Would that be correct? Would there be any other way? (I dont want to use gdal_translate for this process).
1 Answer
That will work as long as your images aren't rotated, i.e. gt[2] == gt[4] == 0
. Have a look at rasterio if you're not tied to straight-up gdal: https://rasterio.readthedocs.io/en/latest/topics/windowed-rw.html#data-windows
-
In my case they are projected images with no rotation. I didnt know what those numbers (gt[2] == gt[4]) were. Where can I read about what the values of the GeoTransform tuple mean? Thx Commented Aug 2, 2018 at 0:09
-
Those are the x and y rotation coefficients. See here: gdal.org/gdal_datamodel.html#gdal_datamodel_dataset_gtm– mikewattCommented Aug 2, 2018 at 0:17
-
More info can be read from webhelp.esri.com/arcgisdesktop/9.3/… - a GDAL GeoTransform object is similar to the values in a world file (slightly different order) gdal.org/gdal_tutorial.html and search for adfGeoTransform. there are some comments there that might help. Commented Aug 2, 2018 at 0:24