arcgis python脚本修改属性表_ArcGIS & python学习:(一)批处理修改文件名(NDVI数据)...

下载的NDVI数据,一共26年,每年有24个文件夹(每月2个),每个文件夹下3个文件,文件名很长,类似这样的:“Subset_China_EA85aug15b.n09-VIg_albers_TIFF.tif”,看着太累,而且之后处理需要每年的放在一个文件夹下,批量修改文件名容易出错且累死,用python很快可以做到。

Center

Center

Center

折腾了1天,总算倒腾出来了,先记录一下(环境:ArcGIS10.0,python2.6):

# -*- coding: cp936 -*-

import os.path

from os.path import join, getsize

print "----------------------Rename Begin--------------------------"

srcdir = "F://other//pythontest//2006"

for root, dirs, files in os.walk(srcdir):

for file in files:

#文件名(除去后缀名)

filename = os.path.splitext(file)[0][0:]

#后缀名

sufix = os.path.splitext(file)[1]

#获取年份、月份、上或下月ab

year = filename[15:-26]

month = filename[17:-23]

updownmonth = filename[22:-20]

#print "year is ", year

#print "month is ", month

#print "updownmonth is ", updownmonth

if month == "jan":

newmonth = "01"

elif month == "feb":

newmonth = "02"

elif month == "mar":

newmonth = "03"

elif month == "apr":

newmonth = "04"

elif month == "may":

newmonth = "05"

elif month == "jun":

newmonth = "06"

elif month == "jul":

newmonth = "07"

elif month == "aug":

newmonth = "08"

elif month == "sep":

newmonth = "09"

elif month == "oct":

newmonth = "10"

elif month == "nov":

newmonth = "11"

elif month == "dec":

newmonth = "12"

else:

print "*****未找到当前月份*******"

#新的名称

tempname = year + newmonth + updownmonth

destfile = srcdir +"//"+ tempname +sufix

file = os.path.join(srcdir,file);

print "destfile is ",destfile

#print "file is ",file

#更改名称

os.rename(file, destfile)

print "-----------------------end----------------------------"

修改后,文件名缩短了,看着舒服多了。

40379213.jpg?x-oss-process=image%2Fformat,webp

下一步,再研究拷贝文件,把每年24个半月文件放在一个目录下,然后批量实现ArcGIS下的MVC最大合成,裁剪等。

转载自:https://mtr-1.oss-cn-beijing.aliyuncs.com/qyblog/2019/04/40379213.jpg

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值