OTB geotransform not written
Different behaviors are observed with OTB 7.2 and OTB 8.0 alpha when writing the output geotransform of products in some corner cases.
For example with Romania_Extract.tif from the OTB test data:
The image has no projection, one gcp with no projection attached:
gdalinfo ~/OTB/otb/Data/Input/Romania_Extract.tif Driver: GTiff/GeoTIFF Files: /home/cedric/OTB/otb/Data/Input/Romania_Extract.tif Size is 200, 200 Coordinate System is `' GCP Projection = GCP[ 0]: Id=1, Info= (0,0) -> (0,0,0) Image Structure Metadata: COMPRESSION=LZW INTERLEAVE=PIXEL Corner Coordinates: Upper Left ( 0.0, 0.0) Lower Left ( 0.0, 200.0) Upper Right ( 200.0, 0.0) Lower Right ( 200.0, 200.0) Center ( 100.0, 100.0) Band 1 Block=200x1 Type=Float64, ColorInterp=Gray Band 2 Block=200x1 Type=Float64, ColorInterp=Undefined Band 3 Block=200x1 Type=Float64, ColorInterp=Undefined Band 4 Block=200x1 Type=Float64, ColorInterp=Undefined
RigidTransformResample is applied to this image, this application will downscale this image by a factor of 2 :
otbcli_RigidTransformResample -in Romania_Extract.tif -out out.tif -transform.type.id.scalex 2 -transform.type.id.scaley 2
With OTB 7.2, the output image has a non trivial geotransform and no GCP:
gdalinfo out.tif Driver: GTiff/GeoTIFF Files: /tmp/out.tif Size is 400, 400 Origin = (0.000000000000000,0.000000000000000) Pixel Size = (0.500000000000000,0.500000000000000) Image Structure Metadata: INTERLEAVE=PIXEL Corner Coordinates: Upper Left ( 0.0000000, 0.0000000) Lower Left ( 0.000, 200.000) Upper Right ( 200.000, 0.000) Lower Right ( 200.000, 200.000) Center ( 100.000, 100.000) Band 1 Block=400x1 Type=Float32, ColorInterp=Gray Band 2 Block=400x1 Type=Float32, ColorInterp=Undefined Band 3 Block=400x1 Type=Float32, ColorInterp=Undefined Band 4 Block=400x1 Type=Float32, ColorInterp=Undefined
With OTB 8.0 the output image has no geotransform (i.e. origin 0,0 and spacing 1,1) and no GCP:
Driver: GTiff/GeoTIFF Files: /out.tif Size is 400, 400 Metadata: DataType=10 METADATATYPE=OTB OTB_VERSION=8.0.0 TileHintX=200 TileHintY=5 Image Structure Metadata: INTERLEAVE=PIXEL Corner Coordinates: Upper Left ( 0.0, 0.0) Lower Left ( 0.0, 400.0) Upper Right ( 400.0, 0.0) Lower Right ( 400.0, 400.0) Center ( 200.0, 200.0) Band 1 Block=400x1 Type=Float32, ColorInterp=Gray Band 2 Block=400x1 Type=Float32, ColorInterp=Undefined Band 3 Block=400x1 Type=Float32, ColorInterp=Undefined Band 4 Block=400x1 Type=Float32, ColorInterp=Undefined
GCP, Geotransform, GDAL and OTB
In GDAL a dataset should not have a geotransform and GCPs (the behavior is undefined in this case). However OTB images can have both GCP and non trivial origin. When writing an image OTB decides whether the geoTransform or the GCPs should be written:
- If the image has a projection defined, write the projection and write the geotransform
- Else if the image has a sensor model, write it and write the geotransform
- Else if the image has GCPs write them but do not write the geotransform
- Else write the geotransform
In addition, the geo transform is not written if it is trivial (origin 0,0 and spacing 1,1 in GDAL coordinate convention)
This behavior is the same in OTB 7.2.0 and OTB 8.0.0, even if the implementation differ (GCP, projection and sensor models are not stored in the same manner)
GCP and GCP projection
If the dataset has GCP, but no GCP projection attached, the GCP are not read, apparently this is a fix for Alos datasets that reports an unitialized number of GCPs.
This explains the behavior of OTB 7.2, the GCP has no projection attached, it is not read, therefore OTB write the geotransform (last case in section above)
In OTB 8.0 however, the GCP is not read, but the GCP struct is initialized and the image is considered to have GCPs because the GCP object exists in OTB metadata (https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/-/blob/8.0.0-alpha1/Modules/IO/IOGDAL/src/otbGDALImageIO.cxx#L864). This is a bug and should be modified.