我在進行DEM數(shù)據(jù)的裁剪時,發(fā)現(xiàn)各個省的數(shù)據(jù)量非常大,比如說四川省的30m的DEM數(shù)據(jù)的大小為2G??紤]到有限的電腦磁盤空間,我對Tif文件采用了LZW壓縮。
#文件夾中每個文件都進行壓縮 # -*- coding: utf-8 -*- import rasterio as rio import rasterio import os from tqdm import tqdm #每個線程選擇一個文件夾 Input_path ="輸入文件夾"+"\\" Output_path ="輸出文件夾"+"\\" #文件列表 pathDir= os.listdir(Input_path) #壓縮函數(shù) for i in tqdm(range(len(pathDir))): # 讀入柵格文件 rasterfile = Input_path+"\\"+pathDir[i] #打開柵格 rasterdata = rio.open(rasterfile) #讀取柵格 rasterdata2= rasterdata.read() #獲取柵格信息 profile = rasterdata.profile print(profile) #選擇壓縮方式 profile.update( compress='lzw', #壓縮方式:rle,lzw等 ) #導(dǎo)出文件路徑與名字 out_put_name=Output_path +"RLE"+pathDir[i] #導(dǎo)出 with rasterio.open(out_put_name, mode='w', **profile) as dst: dst.write(rasterdata2)
首先是四川省的原始文件大小為2.23Gb,壓縮后的大小為0.99Gb,壓縮了大概一半。
以上就是使用Python批量壓縮tif文件操作步驟的詳細(xì)內(nèi)容,更多關(guān)于Python批量壓縮文件的資料請關(guān)注腳本之家其它相關(guān)文章!
標(biāo)簽:懷化 蘭州 廣西 呂梁 蕪湖 安康 紹興 吉安
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《使用Python批量壓縮tif文件操作步驟》,本文關(guān)鍵詞 使用,Python,批量,壓縮,tif,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。