Import/Export of GeoTIFF loses important header tags
GIMP version: 2.10.20
Operating System: Linux/Windows
Package: flatpak
Description of the bug
A GeoTIFF has spatial coordinates embedded in it so the image (an aerial photograph or scan of a map) can be properly aligned in geospatial software like QGIS. When opening these GeoTIFFs in GIMP, these spatial headers are lost.
Reproduction
Is the bug reproducible? Always
Reproduction steps:
I use the GDAL command line tools to inspect these files, specifically gdalinfo.
- Attached 03376_02_1885-0044L-rescale.tif is the original image (downloaded from the Library of Congress and then rescaled in GIMP) before it's been "georeferenced" in QGIS.
gdalinfo
output (note the GTiff driver is used, even though the tags are incomplete):
$ gdalinfo 03376_02_1885-0044L-rescale.tif
Driver: GTiff/GeoTIFF
Files: 03376_02_1885-0044L-rescale.tif
Size is 1000, 1439
Metadata:
TIFFTAG_DATETIME=2020:09:21 11:17:23
TIFFTAG_DOCUMENTNAME=03376_02_1885-0044L-rescale.tif
TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
TIFFTAG_SOFTWARE=GIMP 2.10.20
TIFFTAG_XRESOLUTION=72
TIFFTAG_YRESOLUTION=72
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 1439.0)
Upper Right ( 1000.0, 0.0)
Lower Right ( 1000.0, 1439.0)
Center ( 500.0, 719.5)
Band 1 Block=1000x128 Type=Byte, ColorInterp=Red
Band 2 Block=1000x128 Type=Byte, ColorInterp=Green
Band 3 Block=1000x128 Type=Byte, ColorInterp=Blue
- After the image has been georeferenced in QGIS, it now has the full GeoTIFF tags in it. See attached imaged 03376_02_1885-0044L-rescale_modified.tif
gdalinfo
output:
$ gdalinfo 03376_02_1885-0044L-rescale_modified.tif
Driver: GTiff/GeoTIFF
Files: 03376_02_1885-0044L-rescale_modified.tif
Size is 1663, 1749
Coordinate System is:
PROJCRS["WGS 84 / Pseudo-Mercator",
BASEGEOGCRS["WGS 84",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4326]],
CONVERSION["Popular Visualisation Pseudo-Mercator",
METHOD["Popular Visualisation Pseudo Mercator",
ID["EPSG",1024]],
PARAMETER["Latitude of natural origin",0,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8801]],
PARAMETER["Longitude of natural origin",0,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8802]],
PARAMETER["False easting",0,
LENGTHUNIT["metre",1],
ID["EPSG",8806]],
PARAMETER["False northing",0,
LENGTHUNIT["metre",1],
ID["EPSG",8807]]],
CS[Cartesian,2],
AXIS["easting (X)",east,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["northing (Y)",north,
ORDER[2],
LENGTHUNIT["metre",1]],
USAGE[
SCOPE["unknown"],
AREA["World - 85°S to 85°N"],
BBOX[-85.06,-180,85.06,180]],
ID["EPSG",3857]]
Data axis to CRS axis mapping: 1,2
Origin = (-10026380.531483946368098,3498938.994203031063080)
Pixel Size = (0.336598211455628,-0.336598211455628)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left (-10026380.531, 3498938.994) ( 90d 4' 6.63"W, 29d57'50.84"N)
Lower Left (-10026380.531, 3498350.284) ( 90d 4' 6.63"W, 29d57'34.35"N)
Upper Right (-10025820.769, 3498938.994) ( 90d 3'48.53"W, 29d57'50.84"N)
Lower Right (-10025820.769, 3498350.284) ( 90d 3'48.53"W, 29d57'34.35"N)
Center (-10026100.650, 3498644.639) ( 90d 3'57.58"W, 29d57'42.60"N)
Band 1 Block=1663x1 Type=Byte, ColorInterp=Red
NoData Value=0
Band 2 Block=1663x1 Type=Byte, ColorInterp=Green
NoData Value=0
Band 3 Block=1663x1 Type=Byte, ColorInterp=Blue
NoData Value=0
- Opening this file up in GIMP works just like any other tif. When it's exported with default settings (no compression etc.) you can see that the spatial information has disappeared: 03376_02_1885-0044L-rescale_modified_GIMPexport.tif.
gdalinfo
output:
$ gdalinfo 03376_02_1885-0044L-rescale_modified_GIMPexport.tif
Warning 1: TIFFFetchNormalTag:Incompatible type for "GeoPixelScale"; tag ignored
Warning 1: TIFFFetchNormalTag:Incompatible type for "GeoTiePoints"; tag ignored
Warning 1: TIFFFetchNormalTag:Incompatible type for "GeoKeyDirectory"; tag ignored
Driver: GTiff/GeoTIFF
Files: 03376_02_1885-0044L-rescale_modified_GIMPexport.tif
Size is 1663, 1749
Metadata:
TIFFTAG_DATETIME=2020:09:21 11:23:34
TIFFTAG_DOCUMENTNAME=03376_02_1885-0044L-rescale_modified_GIMPexport.tif
TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
TIFFTAG_SOFTWARE=GIMP 2.10.20
TIFFTAG_XRESOLUTION=72
TIFFTAG_YRESOLUTION=72
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 1749.0)
Upper Right ( 1663.0, 0.0)
Lower Right ( 1663.0, 1749.0)
Center ( 831.5, 874.5)
Band 1 Block=1663x128 Type=Byte, ColorInterp=Red
NoData Value=0
Band 2 Block=1663x128 Type=Byte, ColorInterp=Green
NoData Value=0
Band 3 Block=1663x128 Type=Byte, ColorInterp=Blue
NoData Value=0
There's more going on here than I understand, but this should be enough info to get started.