[gdal-dev] TIF + TFW to GeoTIFF without decompression/recompression

Rahkonen Jukka (MML) jukka.rahkonen at maanmittauslaitos.fi
Mon Sep 20 04:20:36 PDT 2021


Hi,

Sorry for not reading your mail till the end after the signature.

I was wondering now if gdal_merge.py with the -createonly option could be useful for a user like me who can't program can use workarounds. However, for some reason the final step with geotifcp fails.

I first checked that combining baseline.tif and baseline.tfw succeeds and it did.
geotifcp  -e baseline.tfw baseline.tif baseline_plus_geo.tif

Creating an empty geotif with gdal_merge is fast
gdal_merge -o mergetest.tif -createonly geotiff.tif

Copying GeoTIFF tags with the -g option fails always. I tried also non-empty GeoTIFFs as the source for the metadata.
geotifcp  -g mergetest.tif baseline.tif baseline_plus_merge.tif
mode=w
geo_print.c DefaultRead failed to read anything.
Failure in GTIFImport

-Jukka Rahkonen-




-----Alkuperäinen viesti-----
Lähettäjä: Rahkonen Jukka (MML) 
Lähetetty: maanantai 20. syyskuuta 2021 12.24
Vastaanottaja: 'Andrea Giudiceandrea' <andreaerdna at libero.it>
Kopio: 'gdal-dev at lists.osgeo.org' <gdal-dev at lists.osgeo.org>
Aihe: Re: [gdal-dev] TIF + TFW to GeoTIFF without decompression/recompression

Hi,

Have you considered to use https://gdal.org/programs/gdal_edit.html?

-Jukka Rahkonen-

-----Alkuperäinen viesti-----
Lähettäjä: gdal-dev <gdal-dev-bounces at lists.osgeo.org> Puolesta Andrea Giudiceandrea via gdal-dev
Lähetetty: maanantai 20. syyskuuta 2021 12.11
Vastaanottaja: gdal-dev at lists.osgeo.org
Aihe: [gdal-dev] TIF + TFW to GeoTIFF without decompression/recompression

Hi devs,
gdal_transalte has an "hidden" feature (not mentioned in the docs [1]), introduced since GDAL 1.10 [2], which allows to convert .JPG + .JPW raster layer to GeoTIFF without decompressing and recompressing the raster image (a so called "lossless conversion of JPEG into JPEG-in-TIFF" [3]).

It seem to me the same is not possible if the source is a .TIF (e.g. a
JPEG-in-TIFF) + .TFW raster layer. In this case the image is always decompressed and then recompressed if a compression method is specified, thus adding another unnecessary lossy step.

I think the decompression / recompression cycle should obviously not be needed converting a TIFF file to a GeoTIFF file (unless image manipulation options are specified) and gdal_transalte should just copy the source TIF file and add the proper GeoTIFF metadata tags taken from the TFW file and from the -a_srs parameter.

Maybe is there any other "hidden" feature I haven't been able to find yet?

Best regards.

Andrea Giudiceandrea


[1] https://github.com/OSGeo/gdal/issues/4510
[2]
https://github.com/OSGeo/gdal/commit/a77c726484d508f1ffff2b9f5a9a869313092687
[3]
https://erouault.blogspot.com/2014/04/advanced-jpeg-in-tiff-uses-in-gdal.html


Side notes:

I know gdal_edit could also be used, but it cannot automatically take the georeferencing parameters from the TFW file.

It could also be possible to use the geotifcp cli tool from libgeotiff, but it seems it (the one shipped by OSGeo4W) has some issues handling JPEG-in-TIFF files (while it works well with other compression formats): 
the "Warning, fractional scanline discarded." and "JPEGLib: Application transferred too few scanlines." errors are reported unsuccessfully trying to convert a JPEG-in-TIFF + TFW to a GeoTIFF.

Instead, the very old and almost nowhere to be found GeoTiffExamin gui tool can just add the proper GeoTIFF metadata tags, taken from the TFW file, to a TIFF file without modifying the raster image. Anyway the gui tool cannot be used for batch conversion.
_______________________________________________
gdal-dev mailing list
gdal-dev at lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list