gdal影像镶嵌并裁剪
生活随笔
收集整理的這篇文章主要介紹了
gdal影像镶嵌并裁剪
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 5 20:18:49 2022@author: 隕星落云
"""
import os
from osgeo import gdaldef mergeAndClip(img_dir,clip_shp,out_dir):files = [os.path.join(img_dir,s)for s in sorted(os.listdir(img_dir))]merged_vrt = os.path.join(img_dir,"merged.vrt")clip_merged = os.path.join(img_dir,"clip_merged.vrt")gdal.BuildVRT(merged_vrt,files)#translate_options = gdal.TranslateOptions(format = 'GTiff',creationOptions = ['TFW=YES', 'COMPRESS=LZW'])gdal.Warp(clip_merged,merged_vrt,cutlineDSName=clip_shp,cropToCutline=True,dstNodata=-9999)gdal.Translate(out_dir,clip_merged)os.remove(merged_vrt)#os.remove(clip_merged)if __name__ == '__main__': img_dir = "D:\\Lake\\2017\\tiles" # 待鑲嵌的影像clip_shp = "D:\\Lake\\2017\\clip.shp" # 裁剪范圍out_dir = "D:\\Lake\\2017\\cliped_img.tif" # 裁剪的影像mergeAndClip(img_dir,clip_shp,out_dir)
結(jié)果:
總結(jié)
以上是生活随笔為你收集整理的gdal影像镶嵌并裁剪的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OpenLDAP的基本概念
- 下一篇: Java封装动态编译