Re: [gdal-dev] TIF + TFW to GeoTIFF without decompression/recompression
(Re-adding gdal-dev) Le 21/09/2021 à 13:04, Andrea Giudiceandrea a écrit : Il 20/09/2021 11:28, Even Rouault ha scritto: No, this is not implemented. As you mention below gdal_edit, you could likely do a small script (or an enhancement of gdal_edit that has a -worldfile {filename} option)) to call SetGeoTransform() with a geotransform computed from the worldfile content Hi Even, thank you for your suggestion. Having a -worldfile option for gdal_edit would be good, it would also good to have also an option to use the georeferencing parameters from a PAM sidecar file. I still think the right thing would be to make sure gdal_translate don't do a decompression/recompression cycle if not needed (i.e. when the src raster is a TIFF ad the dst raster is GeoTIFF and no image manipulation options are specified), maybe adding a special option for this case (or a special value for the COMPRESSION option), so the current default behaviour would be preserved. I can't think of any major theoretical or practical obstacle in doing that, apart from actually coding it, as it will be a completely new code path in the GeoTIFF driver, which is a non-trivial one. Anyway, the following minimal Python script (complete code at [1]) just do what I need (i.e. copy the src tif file to a new dst one and copy the georeference information from src to dst): ** shutil.copyfile(src, dst) src = gdal.Open(src) spatialref = src.GetSpatialRef() geotransform = src.GetGeoTransform() src = None dst = gdal.Open(dst,1) dst.SetSpatialRef(spatialref) dst.SetGeoTransform(geotransform) dst = None ** or using GetGCPSpatialRef() / GetGCPs() and SetGCPs() for a georeference with GCPs and not a geotransform. How can I reliably check if the src raster has a georeference with GCPs or with a geotransform so I can appply the correct georeference to the dst raster? GCPs and geotransform will generally be exclusive (in GeoTIFF they are), so you can for example test if GetGCPs() returns something and use SetGCPs() then, and otherwise do the above Thank you again. Andrea Giudiceandrea [1] https://gist.github.com/agiudiceandrea/2f0ef1e65858de1a35ef4b27b674c4ce -- http://www.spatialys.com My software is free, but my time generally not. ___ gdal-dev mailing list gdal-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] TIF + TFW to GeoTIFF without decompression/recompression
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' Kopio: 'gdal-dev@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 Puolesta Andrea Giudiceandrea via gdal-dev Lähetetty: maanantai 20. syyskuuta 2021 12.11 Vastaanottaja: gdal-dev@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/a77c726484d508f12b9f5a9a869313092687 [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@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev ___ gdal-dev mailing list gdal-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] TIF + TFW to GeoTIFF without decompression/recompression
Andrea, Le 20/09/2021 à 11:11, Andrea Giudiceandrea via gdal-dev a écrit : 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? No, this is not implemented. As you mention below gdal_edit, you could likely do a small script (or an enhancement of gdal_edit that has a -worldfile {filename} option)) to call SetGeoTransform() with a geotransform computed from the worldfile content Best regards. Andrea Giudiceandrea [1] https://github.com/OSGeo/gdal/issues/4510 [2] https://github.com/OSGeo/gdal/commit/a77c726484d508f12b9f5a9a869313092687 [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@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev -- http://www.spatialys.com My software is free, but my time generally not. ___ gdal-dev mailing list gdal-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev
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 Puolesta Andrea Giudiceandrea via gdal-dev Lähetetty: maanantai 20. syyskuuta 2021 12.11 Vastaanottaja: gdal-dev@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/a77c726484d508f12b9f5a9a869313092687 [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@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev ___ gdal-dev mailing list gdal-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev
[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/a77c726484d508f12b9f5a9a869313092687 [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@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev