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

Travis Kirstine traviskirstine at gmail.com
Wed Sep 12 07:27:20 PDT 2018


Kristofer,

Could you use the gdal createcopy method first to create the 'second' image
before opening it with pyvips


fileformat = "GTiff"
driver = gdal.GetDriverByName(fileformat)
src_ds = gdal.Open(src_filename)
dst_ds = driver.CreateCopy(dst_filename, src_ds, strict=0)
# Once we're done, close properly the dataset
dst_ds = None
src_ds = None

Regards


On Wed, 12 Sep 2018 at 04:48, krikr42 <kristofer.krus at liu.se> wrote:

> Hi,
>
> I have two tiff images, of which the first one is a GeoTIFF image and the
> second is a tiff image created from the first one by opening it with pyvips
> in Python, modifying it (blurring it) and saving it as a new file (so I
> don't know whether the second image counts as a GeoTIFF file). However, the
> second image lacks a lot of metadata that exists in the first image which I
> need, such as the coordinate system and corner coordinates.
>
> How can I read this metadata from the first file with GDAL (in Python,
> although I guess the C++ API is pretty similar)? I have already tried
> loading the file as a GDAL dataset using  gdal.Open
> <https://gdal.org/python/osgeo.gdal-module.html>   and reading the data
> with
> the  GetMetadata
> <
> https://www.gdal.org/classGDALMajorObject.html#a8ce3bf5795bbebfe9bc643e2152bb360>
>
> method, and I have looked in the  domains
> <https://www.gdal.org/gdal_datamodel.html>   'SUBDATASETS',
> 'IMAGE_STRUCTURE', 'RPC', 'IMAGERY' as well as the default domain, but none
> of those contain the information about the coordinate system or the
> coordinates. There are supposedly also xml: domains, and I'm wondering
> whether the data I'm looking for may be under an xml domain, but I don't
> know what the name of that domain would be, and I can't find any way to
> list
> available domains (is there any? Because that would be great).
>
> So, how can I read the metadata specifying the coordinate system and corner
> coordinates from the first file and write it to the other? If I can read it
> with GetMetadata, I suppose I will also be able to write it with
> SetMetadata
> <
> https://www.gdal.org/classGDALMajorObject.html#a61ab7226d95b20e3e1f42461a1f62906>
>
> (I was able to do that for the domains listed above).
>
> I have also tried to transfer the information by reading it with the
> command
> line tool gdalinfo and writing it with gdal_translate, but that fails as 1)
> I don't know how to write all the relevant metadata with gdal_translate and
> 2) the metadata that I try to write isn't successfully written as the
> coordinate system information – which looks to be JSON-formatted – ends up
> with a different JSON-tag in the root element and with some elements
> missing.
>
> Regards
>
> Kristofer
>
>
>
> --
> Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20180912/f8fddfa7/attachment.html>


More information about the gdal-dev mailing list