• ArcGIS Python获得岛的个数


    import arcpy
    def getpnum(geometry):
        part_count = geometry.partCount
        if part_count>1:#多部件
            return  999999 
        geo=geometry.getPart(0)
        num=geo.count
        n=0    
        for i in range(num):
            pt=geo[i]
            if pt==None: #空点就是下一个内多边形
                n=n+1     
        return n
    inFeature= arcpy.GetParameterAsText(0)
    fieldname= arcpy.GetParameterAsText(1)
    with arcpy.da.UpdateCursor(inFeature, [fieldname,"shape@"]) as cursor:
        for row in cursor:
            k=getpnum(row[1])
            arcpy.AddMessage("k:"+str(k))
            row[0] =k
            cursor.updateRow(row)
    #rows = arcpy.UpdateCursor(inFeature)
    #for row in rows:
        
    #    row.setValue(fieldname, getpnum(row.getValue("shape")) )
    #    rows.updateRow(row)
    
    #del row
    #del rows
      

     ============================

    完整代码和视频关注微信公众号

    import arcpy
    
    def getxy(geo):
        partnum = 0
    
        for part in geo:
            # Print the part number
            #print("Part {}:".format(partnum))
            # Step through each vertex in the feature
            for pnt in part:
                if pnt:
                    # Print x,y coordinates of current point
                    print("{}, {}".format(pnt.X, pnt.Y))
                else:
                    # If pnt is None, this represents an interior ring
                    print("Interior Ring:")
            partnum += 1
    def getpartnum(geo):
        partnum = 0
    
        for part in geo:
            # Print the part number
    
            partnum += 1
        return partnum
    
    def getislandnum(geo):
        n = 0
    
        for part in geo:
            # Print the part number
            #print("Part {}:".format(partnum))
            # Step through each vertex in the feature
            for pnt in part:
                if pnt==None:
    
                    # If pnt is None, this represents an interior ring
                    print("Interior Ring:")
                    n=n+1
        return n
    
    infc = arcpy.GetParameterAsText(0)
    inField = arcpy.GetParameterAsText(1)
    # Enter for loop for each feature
    with arcpy.da.UpdateCursor(infc, ["OID@", "SHAPE@",inField]) as cursor:
        for row in cursor:
            # Print the current polygon or polyline's ID
            print("Feature {}:".format(row[0]))
    
            # Step through each part of the feature
            #getxy(row[1])
            #print(getpartnum(row[1]))
            num=getislandnum(row[1])
            print(num)
            row[2]=num
            cursor.updateRow(row)
  • 相关阅读:
    IOCP十:Client退出后投递WSARecv
    IOCP九:Client退出后投递WSASend
    IOCP九:Client退出后投递WSASend
    CPU线程调度
    CPU线程调度
    windows的磁盘操作之八——格式化分区的思考
    windows的磁盘操作之八——格式化分区的思考
    windows的磁盘操作之六——获取系统所在物理磁盘号
    windows的磁盘操作之六——获取系统所在物理磁盘号
    windows的磁盘操作之七——获取当前所有的物理磁盘号
  • 原文地址:https://www.cnblogs.com/gisoracle/p/15187091.html
Copyright © 2020-2023  润新知