Example - Merge

[1]:
import rioxarray # for the extension to load
import xarray
from rioxarray.merge import merge_arrays
# Note: You can merge datasets with the merge_datasets method

%matplotlib inline

Load in xarray dataset

API reference:

[2]:
dem_test = "../../test/test_data/input/MODIS_ARRAY.nc"
rds = rioxarray.open_rasterio(dem_test)
arrays = [
    rds.isel(x=slice(100), y=slice(100)),
    rds.isel(x=slice(100, 200), y=slice(100, 200)),
    rds.isel(x=slice(100), y=slice(100, 200)),
    rds.isel(x=slice(100, 200), y=slice(100)),
]
merged = merge_arrays(arrays)
[3]:
rds.where(rds!=rds.rio.nodata).plot();
../_images/examples_merge_4_0.png
[4]:
merged.where(merged!=merged.rio.nodata).plot()
[4]:
<matplotlib.collections.QuadMesh at 0x7f84f86f13c8>
../_images/examples_merge_5_1.png