Arcpy功能总结
Posted rockman
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Arcpy功能总结相关的知识,希望对你有一定的参考价值。
1. 导入arcpy的库,一般不会超出以下用到的库
import sys, string, os, arcgisscripting
gp = arcgisscripting.create()
gp.CheckOutExtension("spatial")
gp.AddToolbox(r"D:Program Files (x86)ArcGISDesktop10.2ArcToolboxToolboxesSpatial Analyst Tools.tbx")
gp.overwriteOutput=1
import arcpy
from arcpy import env
from arcpy.sa import *
env.cellSize=0.1
# Set environment settings
2. Print Raster平均值、最大值、最小值等
for i in range(2005,2016+1): inRaster = r"K:liuleiGlobalNdata_NOxext"+"/"+str(i)+".tif" print float(str(arcpy.GetRasterProperties_management(inRaster, "MEAN")))
3. 重采样栅格
arcpy.Resample_management(inputfile, outputfile, "2.5 1.8947369", "NEAREST")
4. 裁剪栅格图像
outExtractByMask = ExtractByMask(inRaster, inMaskData) outpath="ext_"+inRaster outExtractByMask.save(outpath) print outpath
5. 统计区域均值、最大、最小总和
inZoneData = "bou2_4p" zoneField = "SixRegions" inValueRaster = "etopa_nh3nn_"+str(i)+"0"+str(j)+"_AM" outTable=str("L:/excel/excelError/" + inValueRaster + ".dbf") outZSaT = ZonalStatisticsAsTable(inZoneData, zoneField, inValueRaster, outTable, "NODATA", "MEAN")
6. 给栅格批量加入投影、地理坐标
str11="DepHNO3_"+str(j)+"_"+str(i) # set local variables in_dataset = str11+".tif" # get the coordinate system by describing a feature class dsc = arcpy.Describe("bou2_4p.shp") coord_sys = dsc.spatialReference # run the tool arcpy.DefineProjection_management(in_dataset, coord_sys) # print messages when the tool runs successfully print(arcpy.GetMessages(0))
7、栅格转点文件
str1=str(i)+"_"+str(j)+"_500"+"m.tif" print str1 inRaster = str1 outpath=rootpath+"/"+str(i)+"_"+str(j)+"_500m"+".shp" field = "VALUE" arcpy.RasterToPoint_conversion(inRaster, outpath, field)
8、 点文件去除异常值
str1=workpath+"/"+"IASINH3_"+str(i)+"_"+str(j)+".shp" print str1 with arcpy.da.UpdateCursor(str1, ["GRID_CODE"]) as cursor: for row in cursor: if row[0] < 0: cursor.deleteRow()
9. 点文件插值成栅格
str1="iasinh3_"+str(i)+"_"+str(j)+".shp" if os.path.exists(r"K:DatasetNH3Version2I2tifv2R dot11shp"+"/"+str1): print str1 inPointFeatures = str1 zField = "GRID_CODE" cellSize = 0.1 power = 2 searchRadius = RadiusVariable(12, 5) outIDW = Idw(inPointFeatures, zField, cellSize, power, searchRadius) outpath=r"K:DatasetNH3Version"+"/"+"IASINH3_"+str(i)+"_"+str(j)+".tif" outIDW.save(outpath)
以上是关于Arcpy功能总结的主要内容,如果未能解决你的问题,请参考以下文章