Modify the layers of a S2 observations and saving the result as a geotiff

4 visualizaciones (últimos 30 días)
Hi community. I am a PhD student.
For research reasons, I should have to read a tif file, corresponding to a S2 observation, change some bands and save the result as a geotiff. Then I should open this modified tif with SNAP, an ESA software and perform some actions, implemented in this software.
In the following code, for the sake of simplicity, I have just created a copy of trial_subset, saved as trial_subset_copiamia.
fn = "trial_subset.tif";
[A,R] = readgeoraster(fn);
info = geotiffinfo(fn);
% metadati per scrittura in tif
geoTags = info.GeoTIFFTags.GeoKeyDirectoryTag;
The problem I encoutered is that, while in the original observation, read in SNAP, I have a certain organization of the optical observation, in the copied one, I don't have such organization (images attached), and this gives me problems in performing some actions in the software SNAP, because the software does not recognize the bands, having them names different from the ones in the original observation.
So, I would like to read a geotiff file, change something and write a new tif file, while maintaining all the metadata (also the name of the bands) of the original observation.
Thanks in advance for your help.
Luca Liverotti

Respuestas (1)

Abhijeet el 16 de Ag. de 2023
Hi Luca,
From the explanation, I understand that you have a geotiff file corresponding to a Sentinel-2 (S2) observation. You want to read this file, modify some bands, and save the modified version as a new geotiff file. However, when you open the modified file in SNAP (ESA software), the organization of the optical observation is different, causing problems because SNAP doesn't recognize the bands with their original names.
To address this issue, you would like to find a way to read a geotiff file, make changes to it while preserving all the metadata (including band names) of the original observation, and then save it as a new geotiff file.
To achieve your goal of modifying the geotiff file while preserving all the metadata, including band names, you can follow these steps:
Read the original geotiff file using the geotiffread function:
[A, R] = geotiffread('trial_subset.tif');
Retrieve the metadata information using the geotiffinfo function:
info = geotiffinfo('trial_subset.tif');
Make the desired modifications to the `A` array, which represents the pixel values of the bands.
Write the modified data to a new geotiff file using the geotiffwrite function. To preserve the metadata, including band names, you need to pass the `info` structure obtained from `geotiffinfo` as an argument:
geotiffwrite('trial_subset_modified.tif', A, R, 'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);
By following the above-mentioned steps, you can modify bands with the metadata preserved.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by