使用Python批量压缩tif文件操作步骤

作者:锐多宝的地理空间 时间:2021-03-27 00:04:10 

1.前言

我在进行DEM数据的裁剪时,发现各个省的数据量非常大,比如说四川省的30m的DEM数据的大小为2G。考虑到有限的电脑磁盘空间,我对Tif文件采用了LZW压缩。

2.流程

使用Python批量压缩tif文件操作步骤

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)
#压缩函数
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.结果展示

使用Python批量压缩tif文件操作步骤

首先是四川省的原始文件大小为2.23Gb,压缩后的大小为0.99Gb,压缩了大概一半。

使用Python批量压缩tif文件操作步骤

来源:https://blog.csdn.net/weixin_36396470/article/details/120169261

标签:Python,压缩文件
0
投稿

猜你喜欢

  • Python Web框架之Django框架Form组件用法详解

    2021-10-21 11:12:39
  • selenium+python实现自动化登录的方法

    2021-08-07 13:38:08
  • 此数据库没有有效所有者,因此无法安装数据库关系图支持对象

    2012-01-29 18:15:11
  • python检查字符串是否是正确ISBN的方法

    2022-05-10 14:54:01
  • 关于asp分页的新想法

    2008-09-06 12:53:00
  • php利用ob_start()清除输出和选择性输出的方法

    2023-11-18 08:54:35
  • 写给应聘页面重构的同学

    2009-03-18 11:01:00
  • python 3利用Dlib 19.7实现摄像头人脸检测特征点标定

    2022-07-31 05:54:21
  • UTF-8转为GB2312编码的asp函数

    2007-08-23 13:42:00
  • Asp 单页查询数据库

    2010-05-11 20:11:00
  • MySQL查询优化

    2009-03-09 14:41:00
  • 解密SQL Server数据库系统的编译

    2009-03-16 17:33:00
  • python-字典dict和集合set

    2021-09-30 10:10:17
  • web前端页面性能优化

    2009-08-15 12:31:00
  • Django csrf校验的实现

    2023-10-01 14:49:40
  • 错误的随机数_JavaScript

    2009-08-28 12:43:00
  • 20个优秀网站助你征服CSS[译]

    2008-09-21 13:21:00
  • 利用Python实现Json序列化库的方法步骤

    2023-01-15 07:03:00
  • File input 的样式和文字的更改方法__适用于Firefox、IE等浏览器

    2009-10-13 21:05:00
  • python中argparse模块基础及使用步骤

    2023-01-26 19:21:59
  • asp之家 网络编程 m.aspxhome.com