Merge raster data with GDAL in Python. Alexis Outdoors November, 2020. 00000
Merge raster data with GDAL in Python [link]Paper  abstract   bibtex   
This tutorial explains how to merge a bunch of raster tiles from the same directory to a single geotiff file using GDAL in Python. There are two options to merge raster data with GDAL: 1) run gdal_merge.py with subprocess 2) build a virtual mosaic of all raster files and convert that to geotiff. GDAL/OGR Python API: https://gdal.org/python/ Code: from osgeo import gdal import glob import subprocess # list all files in directory that match pattern demList = glob.glob("dem[0-9][0-9].tif") print(demList) # gdal_merge cmd = "gdal_merge.py -ps 10 -10 -o mergedDEM.tif" subprocess.call(cmd.split()+demList) # build virtual raster and convert to geotiff vrt = gdal.BuildVRT("merged.vrt", demList) gdal.Translate("mergedDEM2.tif", vrt, xRes = 10, yRes = -10) vrt = None
@misc{alexis_outdoors_merge_2020,
	title = {Merge raster data with {GDAL} in {Python}},
	url = {https://www.youtube.com/watch?v=sBBMKbAj8XE},
	abstract = {This tutorial explains how to merge a bunch of raster tiles from the same directory to a single geotiff file using GDAL in Python. There are two options to merge raster data with GDAL: 1) run gdal\_merge.py with subprocess 2) build a virtual mosaic of all raster files and convert that to geotiff. 

GDAL/OGR Python API: https://gdal.org/python/

Code:

from osgeo import gdal
import glob
import subprocess

\# list all files in directory that match pattern
demList = glob.glob("dem[0-9][0-9].tif")
print(demList)

\# gdal\_merge
cmd = "gdal\_merge.py -ps 10 -10 -o mergedDEM.tif"
subprocess.call(cmd.split()+demList)

\# build virtual raster and convert to geotiff
vrt = gdal.BuildVRT("merged.vrt", demList)
gdal.Translate("mergedDEM2.tif", vrt, xRes = 10, yRes = -10)
vrt = None},
	urldate = {2020-12-22},
	author = {{Alexis Outdoors}},
	month = nov,
	year = {2020},
	note = {00000},
}

Downloads: 0