Merge raster data with GDAL in Python. Alexis Outdoors November, 2020. 00000
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
{"_id":"wMFEf85YL48TB7kqj","bibbaseid":"alexisoutdoors-mergerasterdatawithgdalinpython-2020","author_short":["Alexis Outdoors"],"bibdata":{"bibtype":"misc","type":"misc","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":[{"firstnames":[],"propositions":[],"lastnames":["Alexis Outdoors"],"suffixes":[]}],"month":"November","year":"2020","note":"00000","bibtex":"@misc{alexis_outdoors_merge_2020,\n\ttitle = {Merge raster data with {GDAL} in {Python}},\n\turl = {https://www.youtube.com/watch?v=sBBMKbAj8XE},\n\tabstract = {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. \n\nGDAL/OGR Python API: https://gdal.org/python/\n\nCode:\n\nfrom osgeo import gdal\nimport glob\nimport subprocess\n\n\\# list all files in directory that match pattern\ndemList = glob.glob(\"dem[0-9][0-9].tif\")\nprint(demList)\n\n\\# gdal\\_merge\ncmd = \"gdal\\_merge.py -ps 10 -10 -o mergedDEM.tif\"\nsubprocess.call(cmd.split()+demList)\n\n\\# build virtual raster and convert to geotiff\nvrt = gdal.BuildVRT(\"merged.vrt\", demList)\ngdal.Translate(\"mergedDEM2.tif\", vrt, xRes = 10, yRes = -10)\nvrt = None},\n\turldate = {2020-12-22},\n\tauthor = {{Alexis Outdoors}},\n\tmonth = nov,\n\tyear = {2020},\n\tnote = {00000},\n}\n\n","author_short":["Alexis Outdoors"],"key":"alexis_outdoors_merge_2020","id":"alexis_outdoors_merge_2020","bibbaseid":"alexisoutdoors-mergerasterdatawithgdalinpython-2020","role":"author","urls":{"Paper":"https://www.youtube.com/watch?v=sBBMKbAj8XE"},"metadata":{"authorlinks":{}},"html":""},"bibtype":"misc","biburl":"https://bibbase.org/zotero/fortinm","dataSources":["TLSfqfvpu3sQJ89pA"],"keywords":[],"search_terms":["merge","raster","data","gdal","python","alexis outdoors"],"title":"Merge raster data with GDAL in Python","year":2020}