Geographic Information Systems Asked by Hade on February 8, 2021
I try to merge some multiband rasterfiles (Sentinel 2 data) with Rasterio into a single rasterfile but the result is incorrect.
The files are too big to fit in my RAM completely, but I have enough SWAP and I don’t get a Error Message.
Any ideas, what could have gone wrong?
My code:
import rasterio
from rasterio.merge import merge
import glob
files = glob.glob("../data_multiband/*.tif")
mosaic = []
for file in files:
tmp = rasterio.open(file)
mosaic.append(tmp)
mosaic, out_trans = merge(mosaic)
out_meta = tmp.meta.copy()
out_meta.update({"driver": "GTiff",
"height": mosaic.shape[1],
"width": mosaic.shape[2],
"transform": out_trans})
with rasterio.open("../data_merged/test.tif", "w", **out_meta) as dest:
dest.write(mosaic)
That is how the result looks:
As you can see (red marks) some rasterfiles occur two times. The one on the left side are wrong.
Thats how the original files look:
I solved the problem. The files have the same crs, but are in different zones. Reprojecting solved it
Answered by Hade on February 8, 2021
You may want to use gdalwarp
(or gdal.Warp
if using Python) for this. This will allow you to merge and reproject in one go. Often a good idea to set x/y resolution when reprojecting in case GDAL ends giving you something like 9.34 m rather than 10 m
gdalwarp -t_srs "EPSG:XXXX" -tr X Y in1.tif in2.tif out.tif
Answered by Jose on February 8, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP