时间:2020-08-05 python教程 查看: 1082
1、获取指定位置的点值:
OutputFile = open(statisticResultTXT, 'w')
cellvalue=arcpy.GetCellValue_management(inputfilepath+filenname+".tif",staionXY, "1")
OutputFile.write(stationID+"_"+filenname+""+str(cellvalue)+'\n')
OutputFile.close()
2、获取区域的均值极值
utputFile = open(statisticResult, 'w')
env.workspace = ('E:\loessplateau\ET_Spline\extract_year')
rlist = arcpy.ListRasters('*','tif')
for file in rlist:
minValueInfo= arcpy.GetRasterProperties_management(file,'MINIMUM')
minValue = minValueInfo.getOutput(0)
maxValueInfo = arcpy.GetRasterProperties_management(file,'MAXIMUM')
maxValue = maxValueInfo.getOutput(0)
meanValueInfo = arcpy.GetRasterProperties_management(file,'MEAN')
meanValue = meanValueInfo.getOutput(0)
print file + ',' + str(minValue) + ',' + str(maxValue) + ',' + str(meanValue) +'\n'
OutputFile.write(file + ',' + str(minValue) + ',' + str(maxValue) + ',' + str(meanValue) +'\n')
OutputFile.close()
补充知识:python_计算格点数据降水变化斜率
我就废话不多说了,还是直接看代码吧!
import numpy as np
import pandas as pd
import codecs
path=r'C:\try.csv' #读取格点数据CSV
data=pd.read_csv(path,encoding='gbk')
outpath=r'C:\rate.csv'#新建存放斜率的CSV
file_csv = codecs.open(outpath,'w+','utf-8') #打开方式
data1=data.T #转置
n=80 #格点数
m=17 #年数
sl=[] #空列表
for i in list(range(0,80)):#循环计算80个格点的变化斜率
print (i)
sp=[]
y=data1[i]
y=y.values
for k in range(0,m-1):
for j in range(k+1,m):
print(k,j)
s=(y[j]-y[k])/(j-k) #计算斜率
sp.append(s)
sl.append(np.median(sp))
slop= pd.DataFrame(sl)
slop.to_csv(outpath,header=['slop']) #将SLOP写入CSV
以上这篇python获取栅格点和面值的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持python博客。