标签:file save dsc rip pre 裁剪 dataset string otp
1. 导入arcpy的库,一般不会超出以下用到的库
import sys, string, os, arcgisscripting
gp = arcgisscripting.create()
gp.CheckOutExtension("spatial")
gp.AddToolbox(r"D:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Toolboxes\Spatial 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:\liulei\GlobalN\data_NOx\ext"+"/"+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:\Dataset\NH3\Version2I\2tif\v2R\0dot1\1shp"+"/"+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:\Dataset\NH3\Version"+"/"+"IASINH3_"+str(i)+"_"+str(j)+".tif" outIDW.save(outpath)
标签:file save dsc rip pre 裁剪 dataset string otp
原文地址:https://www.cnblogs.com/rockman/p/13418209.html