zoukankan      html  css  js  c++  java
  • [ArcPy Tips-4] 找到一个ShapeFile里面积最大的多边形!

    import arcpy,os,sys
    import arcpy.da
    
    srcDir = "E:\Sentinel_1\2018S1\"##自行修改,shp所在的目录
    
    for file in os.listdir(srcDir):
        if os.path.splitext(file)[1] == ".shp":
            print(file)
            input = file
            areaShp = "AREA_"+file
            if not os.path.exists(srcDir+"\"+areaShp):
                featureCount = arcpy.GetCount_management(srcDir+"\"+input)[0]
                if int(featureCount)>0:
                    print(input)
                    arcpy.CalculateAreas_stats(srcDir+"\"+input, srcDir+"\"+areaShp)
    
            maxPolygonID = 0
            maxArea = 0
            with arcpy.da.SearchCursor(srcDir+"\"+areaShp,("Id","F_AREA")) as cursor: #Id需为唯一值
                for row in sorted(cursor):
                    print(str(row[0])+"_"+str(row[1]))
                    if row[1] > maxArea:
                        maxArea = row[1]
                        maxPolygonID = row[0]
            
            maxPolygonShp = "MAX_Polygon_"+file
            arcpy.Select_analysis(srcDir+"\"+areaShp,srcDir+"\"+maxPolygonShp," Id = "+str(maxPolygonID))
  • 相关阅读:
    数据结构上机思考
    hdu1005,循环节
    网络赛总结
    icpc沈阳网络赛。cake cake!
    树的基础代码
    网络赛第一场
    欧拉函数
    欧拉函数
    多校第十场
    (环上)最大子段和
  • 原文地址:https://www.cnblogs.com/wszhang/p/15477916.html
Copyright © 2011-2022 走看看