处理日照时数数据,要根据观测站所测得的数据计算整张黄土高原的日照时数分布。
代码如下:
import arcpy
from arcpy import env
from arcpy.sa import *
import os
from netCDF4 import Dataset
import csv
import math
import re
import arcpy.da
import pandas as pd
def get_path(filenames_in,nameExtension):
path_list = []
for root, dirs, files in os.walk(filenames_in):
for file in files:
# print(dir)
if file[-3:] == f"{nameExtension}":
filePath = os.path.join(filenames_in, file)
# print(pathDir)
path_list.append(filePath)
return path_list
def csvToShp(path,outpath):
path = str(path)
name = getName(path)
outpath = outpath + os.path.sep + name + ".shp"
if not os.path.exists(outpath):
nc = arcpy.management.XYTableToPoint(path, outpath, "lon", "Lat")
return outpath
def getName(path):
name = path.split('\\')[-1]
timelist = re.findall("\d+", name)[0]
time = f'{timelist[:4]}y{timelist[4:]}m'
return time
def tifToShp(pointRoot, tifPath, outFilie):
out_path = tifPath.split('\\')[-1]
out_path = outFilie + "\\" + out_path[:-3] + 'shp'
print(out_path)
if os.path.exists(out_path):
pass
else:
nc_Ra = ExtractValuesToPoints(pointRoot, tifPath, out_path, "NONE")
print(1)
print(out_path + '已转换成shp文件')
return nc_Ra
work_space = r"D:\项目文件\Aconada\untitled\SSDcsv"
shpOutPath = r"D:\datasum\pointShp\ssd"
pointRoot = r"D:\datasum\DEM\\slope1.shp"
csvPathList = get_path(work_space,"csv")
for csvPath in csvPathList:
shpPath = csvToShp(csvPath,shpOutPath)
if shpPath == None:
continue
outIDW = Idw(shpPath, "SSD", cell_size=0.0288000000000002)
shpOut_path = shpOutPath + os.path.sep + shpPath.split("\\")[-1][:-4]
ExtractValuesToPoints(pointRoot, outIDW, shpOut_path, "NONE","ALL")
print(shpOut_path," have been writed!")