Merge raster data with GDAL in Python

Описание к видео Merge raster data with GDAL in Python

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

Комментарии

Информация по комментариям в разработке