zoukankan      html  css  js  c++  java
  • 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:DatasetNH3Version2I2tifv2Rdot11shp"+"/"+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)
    

     

      

     

  • 相关阅读:
    AOJ 718.计算GPA
    AOJ 11.Rails
    AOJ 592.神奇的叶子
    AOJ 10.目标柏林
    洛谷P1030求先序排列
    vijos1514天才的记忆
    洛谷2016战略游戏
    LOJ10155数字转换
    洛谷2014选课
    洛谷2015二叉苹果树
  • 原文地址:https://www.cnblogs.com/rockman/p/13418209.html
Copyright © 2011-2022 走看看