Is there in Rasterio any way to create a mosaic?
I tried to google it, but I couldn't find anything, maybe someone else already used it.
I want to use some open source possibilities, I already know of possibility to use gdalmerge, gdalwarp.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
import rasterio import numpy as np from rasterio.merge import merge from rasterio.plot import show src1 = rasterio.open('/path/to/your/raster1') src2 = rasterio.open('/path/to/your/raster2') # Taking a peek to make sure these are the rasters you want... show(src1) show(src2) srcs_to_mosaic = [src1, src2] # The merge function returns a single array and the affine transform info arr, out_trans = merge(srcs_to_mosaic) show(arr) # Check to make sure the merge looks good.
I was just looking for a similar technique and found this method based on the rasterio/merge.py function given here.
You can check out my example with two orthomosaic images here.
However, I'm not sure this is the best method...no doubt the dude himself @sgillies has more insight into this!
rio warp command (see https://github.com/mapbox/rasterio/blob/master/rasterio/rio/warp.py) can be used to make image mosaics. With a little work you could use that function in Python code, not just as a command line program.