使用Python批量壓縮tif文件操作步驟
發(fā)布日期:2022-01-13 10:15 | 文章來源:gibhub
1.
我在進行DEM數(shù)據(jù)的裁剪時,發(fā)現(xiàn)各個省的數(shù)據(jù)量非常大,比如說四川省的30m的DEM數(shù)據(jù)的大小為2G??紤]到有限的電腦磁盤空間,我對Tif文件采用了LZW壓縮。
2.流程
3.批量壓縮代碼
#文件夾中每個文件都進行壓縮 # -*- 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等 ) #導出文件路徑與名字 out_put_name=Output_path +"RLE"+pathDir[i] #導出 with rasterio.open(out_put_name, mode='w', **profile) as dst: dst.write(rasterdata2)
4.結果展示
首先是四川省的原始文件大小為2.23Gb,壓縮后的大小為0.99Gb,壓縮了大概一半。
以上就是使用Python批量壓縮tif文件操作步驟的詳細內(nèi)容,更多關于Python批量壓縮文件的資料請關注本站其它相關文章!
版權聲明:本站文章來源標注為YINGSOO的內(nèi)容版權均為本站所有,歡迎引用、轉載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權,請聯(lián)系alex-e#qq.com處理。
相關文章