Merge resulting in one pixel shift for half the output file


melda.salhab.14@...
 

I'm using merge with method = 'max' to merge two rasters with identical metadata. When I open the output file and the input files in QGIS, the top part of the output raster is perfectly merged, but the bottom part of the output raster seems to have the merged values of the pixel to it's left. Very bizarre. Has anyone experienced anything like this? Code below.


    combinedFloodList = [FluvialCropped_outputfile] + [PluvialCropped_outputfile] 
 
    # Iterate over raster files and add them to list in 'read mode'            
    allFiles = []
    for fp in combinedFloodList:
        src = rs.open(fp)
        allFiles.append(src)
 
    # Merge flood files. Using max pixel by pixel method
    floodArray, out_trans = merge(allFiles, method='max')
 
    # Save results as raster
    ## Update the metadata
    out_meta = allFiles[0].meta.copy()
    out_meta.update({"height": floodArray.shape[1], 
                      "width": floodArray.shape[2],
                      "transform": out_trans})
 
    # Output file name
    floodName = f"Flood_{countryCode}_{adm1Index}.tif"
 
    ## export as a new geotiff 
    FloodMerged_outputfile = Flood_outputFolderPath / floodName
    with rs.open(FloodMerged_outputfile, 'w', **out_meta, compress = 'LZW') as dest:
        dest.write(floodArray)

Join main@rasterio.groups.io to automatically receive all group messages.