<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Kristofer,<div><br></div><div>Could you use the gdal createcopy method first to create the 'second' image before opening it with pyvips</div><div><br></div><div><br></div><div><div>fileformat = "GTiff"</div><div>driver = gdal.GetDriverByName(fileformat)</div></div><div>src_ds = gdal.Open(src_filename)<br></div><div><div>dst_ds = driver.CreateCopy(dst_filename, src_ds, strict=0)</div><div># Once we're done, close properly the dataset</div><div>dst_ds = None</div><div>src_ds = None</div></div><div><br></div><div>Regards</div><div><br></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, 12 Sep 2018 at 04:48, krikr42 <<a href="mailto:kristofer.krus@liu.se">kristofer.krus@liu.se</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I have two tiff images, of which the first one is a GeoTIFF image and the<br>
second is a tiff image created from the first one by opening it with pyvips<br>
in Python, modifying it (blurring it) and saving it as a new file (so I<br>
don't know whether the second image counts as a GeoTIFF file). However, the<br>
second image lacks a lot of metadata that exists in the first image which I<br>
need, such as the coordinate system and corner coordinates.<br>
<br>
How can I read this metadata from the first file with GDAL (in Python,<br>
although I guess the C++ API is pretty similar)? I have already tried<br>
loading the file as a GDAL dataset using  gdal.Open<br>
<<a href="https://gdal.org/python/osgeo.gdal-module.html" rel="noreferrer" target="_blank">https://gdal.org/python/osgeo.gdal-module.html</a>>   and reading the data with<br>
the  GetMetadata<br>
<<a href="https://www.gdal.org/classGDALMajorObject.html#a8ce3bf5795bbebfe9bc643e2152bb360" rel="noreferrer" target="_blank">https://www.gdal.org/classGDALMajorObject.html#a8ce3bf5795bbebfe9bc643e2152bb360</a>>  <br>
method, and I have looked in the  domains<br>
<<a href="https://www.gdal.org/gdal_datamodel.html" rel="noreferrer" target="_blank">https://www.gdal.org/gdal_datamodel.html</a>>   'SUBDATASETS',<br>
'IMAGE_STRUCTURE', 'RPC', 'IMAGERY' as well as the default domain, but none<br>
of those contain the information about the coordinate system or the<br>
coordinates. There are supposedly also xml: domains, and I'm wondering<br>
whether the data I'm looking for may be under an xml domain, but I don't<br>
know what the name of that domain would be, and I can't find any way to list<br>
available domains (is there any? Because that would be great).<br>
<br>
So, how can I read the metadata specifying the coordinate system and corner<br>
coordinates from the first file and write it to the other? If I can read it<br>
with GetMetadata, I suppose I will also be able to write it with <br>
SetMetadata<br>
<<a href="https://www.gdal.org/classGDALMajorObject.html#a61ab7226d95b20e3e1f42461a1f62906" rel="noreferrer" target="_blank">https://www.gdal.org/classGDALMajorObject.html#a61ab7226d95b20e3e1f42461a1f62906</a>>  <br>
(I was able to do that for the domains listed above).<br>
<br>
I have also tried to transfer the information by reading it with the command<br>
line tool gdalinfo and writing it with gdal_translate, but that fails as 1)<br>
I don't know how to write all the relevant metadata with gdal_translate and<br>
2) the metadata that I try to write isn't successfully written as the<br>
coordinate system information – which looks to be JSON-formatted – ends up<br>
with a different JSON-tag in the root element and with some elements<br>
missing.<br>
<br>
Regards<br>
<br>
Kristofer<br>
<br>
<br>
<br>
--<br>
Sent from: <a href="http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html" rel="noreferrer" target="_blank">http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html</a><br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a></blockquote></div>