Naskah:
import arcpy, traceback, sys, os
pntFile=arcpy.GetParameterAsText(0)
rasters=arcpy.GetParameterAsText(1)
rasters=rasters.split(';')
theFields=[x.name.lower() for x in arcpy.ListFields(pntFile)]
result=arcpy.GetCount_management(pntFile)
nF=int(result.getOutput(0))
p=arcpy.Point()
try:
def showPyMessage():
arcpy.AddMessage(str(time.ctime()) + " - " + message)
for raster in rasters:
desc=arcpy.Describe(raster)
theFLD=raster.lower()
arcpy.AddMessage("Sampling "+theFLD)
if not(theFLD in theFields):
try:arcpy.AddField_management(pntFile, theFLD, "FLOAT")
except:
aF=raster.split(os.sep)[-1]
theFLD=aF.split(".")[0]
theFLD="F"+theFLD
arcpy.AddField_management(pntFile, theFLD, "FLOAT")
arcpy.SetProgressor("step", "", 0, nF)
with arcpy.da.UpdateCursor(pntFile,("SHAPE@XY",theFLD)) as rows:
for row in rows:
p.X,p.Y=row[0]
myArray = arcpy.RasterToNumPyArray(raster,p,1,1,-9999)
row[1]=myArray[0,0]
rows.updateRow(row)
arcpy.SetProgressorPosition()
del row,rows
except:
message = "\n*** PYTHON ERRORS *** "; showPyMessage()
message = "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]; showPyMessage()
message = "Python Error Info: " + str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"; showPyMessage()
Antarmuka:
Parameter:
untuk bekerja dari mxd. Berikan nama unik pendek raster pada daftar isi. Script akan membuat bidang nama yang sama dan berupaya mengisinya dengan nilai sel.
Itu lambat, jadi saya menggunakannya dengan kurang dari 1000 poin