Hi everybody,<br /><br />

Thanks for your replies! The method that worked in the end was to use an external tool called <a href="http://geotiff.maptools.org/geotifcp.html" target="_top" rel="nofollow" link="external">geotifcp</a> (as David Strip-2 wrote). For some reason, all methods I tried that involved GDAL only copied parts of the metadata.

<blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' class="quote dark-border-color"><div class="quote light-border-color">
<div class="quote-author" style="font-weight: bold;">Travis Kirstine wrote</div>
<div class="quote-message">
Could you use the gdal createcopy method first to create the 'second' image before opening it with pyvips</div>
</div></blockquote>


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.

<blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' class="quote dark-border-color"><div class="quote light-border-color">
<div class="quote-author" style="font-weight: bold;">Jon Morris wrote</div>
<div class="quote-message">
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. 
</div>
</div></blockquote>


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.

<blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' class="quote dark-border-color"><div class="quote light-border-color">
<div class="quote-author" style="font-weight: bold;">Jon Morris wrote</div>
<div class="quote-message">
bnd_tags = src.GetRasterBand(band).GetMetadata(BASE_METADATA_DOMAIN)
</div>
</div></blockquote>


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.<br /><br />

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?

<blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' class="quote dark-border-color"><div class="quote light-border-color">
<div class="quote-author" style="font-weight: bold;">David Strip-2 wrote</div>
<div class="quote-message">
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:<br />
    listgeo -no_norm original.tif > original.geo<br />
    geotifcp -g original.geo modified.tif modified_geotiff.tif
</div>
</div></blockquote>


That's exactly what I found was working too!

<blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' class="quote dark-border-color"><div class="quote light-border-color">
<div class="quote-author" style="font-weight: bold;">Even Rouault-2 wrote</div>
<div class="quote-message">
You need to use SetGeoTransform() / GetGeoTransform() and SetProjection() /
GetProjectionRef() to transfer georeferencing information.
Overall presentation at <a href="https://gdal.org/gdal_datamodel.html" target="_top" rel="nofollow" link="external">https://gdal.org/gdal_datamodel.html</a>
</div>
</div></blockquote>


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.<br /><br />

Regards<br /><br />

Kristofer

        
        
        
<br/><hr align="left" width="300" />
Sent from the <a href="http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html">GDAL - Dev mailing list archive</a> at Nabble.com.<br/>