[gdal-dev] How to read all metadata from GeoTIFF file?

krikr42 kristofer.krus at liu.se
Thu Sep 20 08:51:47 PDT 2018


Hi everybody,

Thanks for your replies! The method that worked in the end was to use an
external tool called  geotifcp <http://geotiff.maptools.org/geotifcp.html>  
(as David Strip-2 wrote). For some reason, all methods I tried that involved
GDAL only copied parts of the metadata.
Travis Kirstine wrote
> Could you use the gdal createcopy method first to create the 'second'
> image before opening it with pyvips

Why should I copy the dataset that way when I can just copy the file
directly on the file system? The problem is that pyvips doesn't recognize
the GeoTIFF-specific metadata, so the metadata is lost anyway when I open it
in pyvips to edit it.
Jon Morris wrote
> We have a function to transfer the tags manually, but most of the
> information is in the domain without a name - you have to call
> ds.GetMetadata(''). It goes something like this. For the bands, we're only
> copying some items, but you could take out the for loop and copy them all. 

Yes – the domain with an empty name is the default domain, which I also
include in the domains I looped over to fetch the metadata from. It did
contain some of the metadata I wanted to copy, but not any of the metadata
related to the coordinate system and location of the image within that
coordinate system.
Jon Morris wrote
> bnd_tags = src.GetRasterBand(band).GetMetadata(BASE_METADATA_DOMAIN)

I didn't know that raster bands could also contain metadata! Anyway, the
raster bands in my GeoTIFF image don't contain any metadata, that is, they
don't have any entries in any of the existing metadata domains, at least not
for the non-XML domains.

Speaking of which, I'm still wondering how to list available domains,
including XML domains, because there may be some XML domains in the GeoTIFF
file that I'm not aware know of, and the metadata I need to copy could exist
in those. How do you do that?
David Strip-2 wrote
> If you're willing to use command line tools, there is a pair of tools that
> ship with libgeotiff for extracting metadata from a geotiff and importing
> into a tiff to make it a geotiff.    Given a GeoTIFF file named
> original.tif, and a modified file (modified.tif) without the GeoTIFF tags,
> but still the same size and region:
>     listgeo -no_norm original.tif > original.geo
>     geotifcp -g original.geo modified.tif
> modified_geotiff.tif

That's exactly what I found was working too!
Even Rouault-2 wrote
> You need to use SetGeoTransform() / GetGeoTransform() and SetProjection()
> /GetProjectionRef() to transfer georeferencing information.Overall
> presentation at 
> https://gdal.org/gdal_datamodel.html
> <https://gdal.org/gdal_datamodel.html>  
I did that, and that did transfer some of the metadata related to the
coordinate system and location of the image within that coordinate system,
but not all of it. Together with GetMetadata() and SetMetadata(), it seems
to have copied the same metadata as when I used the command line tools
gdalinfo and gdal_translate.

Regards

Kristofer



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20180920/8bb68b86/attachment.html>


More information about the gdal-dev mailing list