arcpy

"""、
取多波段的值 
转ASC
多值到点
"""


在这里插入代码片
# coding:utf-8
import os.path
import shutil
import arcpy
from arcpy import env
from arcpy.conversion import RasterToASCII
from shutil import copyfile
from arcpy.sa import ExtractMultiValuesToPoints
arcpy.CheckOutExtension("spatial")
#全局变量
arcpy.env.workspace = 'D:\\xh'  #输入数据文件夹
Ratif = arcpy.ListRasters("*", "tif")    #指定数据格式
for Ratif1 in Ratif:
    arcpy.env.workspace = 'D:\\xh'
    #make dir
    mypath="d:\\test\\"+Ratif1[:-4]+"\\"  # type: Union[Union[str, unicode], Any]
    ascpath="d:\\test\\"+Ratif1[:-4]+"asc"+"\\"
    os.mkdir(mypath)
    os.mkdir(ascpath)
    source = "D:\\Climate_Data_Asc\\wd_Distri\\"
    filenames = os.listdir(source)
    for filename in filenames:  # type: str
        shutil.copyfile(source+filename, mypath+filename)
        shutil.copyfile(source + filename, ascpath + filename)
    # extract Band data
    for i in range(1,20):
        Name_GPP1 = Ratif1[:-4] +"Band_"+repr(i)+ ".tif"  # 数据输出名称
        outGpp = arcpy.MakeRasterLayer_management(Ratif1, Name_GPP1, "#", Ratif1, i)
        #创建栅格数据图层,第一个参数为输入数据,第二个是名称,
        #第三个参数没弄,第四个是范围,第五个是我需要的波段
        # print (str(outGpp))
        Out_GPP2 = mypath + Name_GPP1  #输出路径加名称
        arcpy.Int_3d(outGpp, Out_GPP2)
        #栅格转ASC
        outASC = ascpath + "Bio" + Name_GPP1[-6:-4] + ".asc"
        RasterToASCII(outGpp, outASC)
    env.workspace = ascpath
    filenames = os.listdir(ascpath)
    for filename in filenames:
        if os.path.splitext(filename)[1] == '.asc':
            # Check out the ArcGIS Spatial Analyst extension license
            arcpy.CheckOutExtension("Spatial")
            inPointFeatures = ascpath + "white-lipped_deer.shp"
            inRasterList=filename
            ExtractMultiValuesToPoints(inPointFeatures, inRasterList, "BILINEAR")
    print ("All have done!")

你可能感兴趣的:(python,arcgis)