gdal icon indicating copy to clipboard operation
gdal copied to clipboard

Support geotiff tfwx files for georeferencing

Open ConorMurphy21 opened this issue 2 years ago • 5 comments

feature request:

tfwx files are approximate world files created by ARCGis when an exact affine transform cannot be used to georeference an image.

Expected behavior and actual behavior.

Currently geotiff files translated next to a tfwx sidecar file will be translated without georeferencing the image using the tfwx file. If this feature were to be implemented the information from the tfwx file would be used to georeference the image.

Steps to reproduce the problem.

Either "gdalinfo myfile" or roundtripping the tif file should reproduce this behavior

Operating system

All

GDAL version and provenance

All

Known Workarounds

ArcGIS users can rectify their files instead of georeferencing them

ConorMurphy21 avatar Jul 10 '23 22:07 ConorMurphy21

@ConorMurphy21 I'm wondering how support for that would be useful: are there datasets where there is just the .tif + .tfwx, without a .tif.aux.xml (or with a .tif.aux.xml that doesn't contain a <GeodataXform> element) ? My understanding is that reading the .tfwx should be the last resort case where the .tif doesn't contain any valid geotiff tags and the .tif.aux.xml file doesn't contain GCPs

rouault avatar Jul 18 '23 17:07 rouault

@rouault From my understanding, when ESRI adjusts georeferencing of geotiffs it creates a .tif + .tfwx + .tif.aux.xml. The .tfwx file in place of the .tfw file. I don't think the .tif.aux.xml or .tif file always store enough information to properly georeference the image on it's own. From esri docs

World files and georeferencing

If the transformation cannot be expressed as a world file, the transformation information will be written in the .aux.xml file and also in the world file, as an approximate affine transformation. This world file that is created will have an x on the end of the extension name. For example, a TIFF image with an approximate affine transformation has the extension .tfwx. Keep in mind that this is not an exact transformation; it is only an approximation.

There is a special case where this text file contains a true affine transformation. If using the Save option on a raster dataset that already contains map coordinates, a text file with the x extension is written. For example, if georeferencing is performed on a TIFF image that already contains map coordinates, then a .tfwx file that contains a true affine transformation will be created.

It seems to me like tfwx files should be used almost exactly like tfw files just with the understanding that it is an estimated affine transform instead of an exact affine transform. I think in a lot of cases the tfwx file won't be needed because there is information in the .tif file, but in the same cases that GDAL falls back on tfw it should probably be able to fall back on tfwx?

From reading other forums I think this is somewhat related to https://github.com/OSGeo/gdal/issues/8083 because ESRI creates tfwx to estimate affine transform, and then GCP's from aux.xml to make it more accurate. Basing this off of this post

ConorMurphy21 avatar Jul 18 '23 22:07 ConorMurphy21

but in the same cases that GDAL falls back on tfw it should probably be able to fall back on tfwx?

from what you quote above, it looks like it would be a non-nominal case where the .tif.aux.xml would have been removed. Looking for the tfwx would be definitely possible, but would require more file probing. So the benefit of doing this isn't totally obvious.

rouault avatar Jul 18 '23 23:07 rouault

hmm I didn't realize GDAL ignores tfw files in the case of the existence of aux.xml files. I think that the point of .tfwx files is to be used in conjunction with aux.xml files. So it would not be super uncommon for this to occur, I think the only requirement for this to occur would be for the georeferencing tags on the internal tif file to be missing? Again based off of https://github.com/OSGeo/gdal/issues/8083 and post

ConorMurphy21 avatar Jul 18 '23 23:07 ConorMurphy21

I'm wondering how support for that would be useful: are there datasets where there is just the .tif + .tfwx, without a .tif.aux.xml (or with a .tif.aux.xml that doesn't contain a element) ?

I have some. These are scanned maps that were georeferenced using ESRI tools in 2009. Each one has .tif, .tif.aux.xml, .tfwx. gdalinfo reports coordinates in pixels and doesn't identify the .tfwx as a sidecar file.

C:\PROGRA~1\QGIS34~2.2>gdalinfo "\\some_folder\some_file.tif"
Driver: GTiff/GeoTIFF
Files: \\some_folder\some_file.tif
       \\some_folder\some_file.tif.aux.xml
Size is 10952, 7238
Metadata:
  TIFFTAG_XRESOLUTION=300
  TIFFTAG_YRESOLUTION=300
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0, 7238.0)
Upper Right (10952.0,    0.0)
Lower Right (10952.0, 7238.0)
Center      ( 5476.0, 3619.0)
Band 1 Block=10952x1 Type=Byte, ColorInterp=Red
Band 2 Block=10952x1 Type=Byte, ColorInterp=Green
Band 3 Block=10952x1 Type=Byte, ColorInterp=Blue

volcan01010 avatar Oct 03 '25 13:10 volcan01010