Created
July 30, 2017 12:05
-
-
Save nishadhka/9bc758129c2949a3194b79570198f544 to your computer and use it in GitHub Desktop.
Raster merge using rasterio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rasterio.merge | |
bounds=None | |
res=None | |
nodata=None | |
precision=7 | |
def merge(input1,bounds, res, nodata, precision): | |
import warnings | |
warnings.warn("Deprecated; Use rasterio.merge instead", DeprecationWarning) | |
return rasterio.merge.merge(input1, bounds, res, nodata, precision) | |
dataset1 = rasterio.open("raster1.tif") | |
dataset2 = rasterio.open("raster2.tif") | |
dest, output_transform=merge([dataset1,dataset2],bounds, res, nodata, precision) | |
with rasterio.open("raster1.tif") as src: | |
out_meta = src.meta.copy() | |
out_meta.update({"driver": "GTiff", | |
"height": dest.shape[1], | |
"width": dest.shape[2], | |
"transform": output_transform}) | |
with rasterio.open("mergedRasters.tif", "w", **out_meta) as dest1: | |
dest1.write(dest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment