你好,“python批量转换:未知类型二进制净生产力(NEP)遥感定量反演产品数据的打开,转换为tif,可用于通用GIS、遥感软件打开”这个有完整的代码吗,我近期也下载了这个数据不知道该怎么处理
根据你在CSDN提出的img文件处理代码咨询问题链接,我的理解和建议如下:
python
import os
path = r'D:\img_folder' # 文件夹路径
for file in os.listdir(path):
if file.endswith('.img') or file.endswith('.IMG'):
# 处理img文件
(2) 重命名img文件,可以使用os.rename()方法。
python
new_name = 'img_' + str(index) + '.jpg' # 新的文件名
os.rename(os.path.join(path, file), os.path.join(path, new_name))
(3) 压缩img文件,可以使用PIL的Image模块。
python
from PIL import Image
img = Image.open(os.path.join(path, file))
img.save(os.path.join(path, new_name), quality=60) # quality为压缩质量
(4) 也可以同时重命名和压缩img文件。
3. 完整代码示例:
python
import os
from PIL import Image
path = r'D:\img_folder'
index = 1
for file in os.listdir(path):
if file.endswith('.img') or file.endswith('.IMG'):
new_name = 'img_' + str(index) + '.jpg'
os.rename(os.path.join(path, file), os.path.join(path, new_name))
img = Image.open(os.path.join(path, new_name))
img.save(os.path.join(path, new_name), quality=60)
index += 1
如果觉得对你有用,帮忙采纳一下哦,谢谢