(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