arcpy计算分级色彩后点个数线长度面面积总和

2023-12-20 17:44:54

需求:

计算分级色彩后,各个级别中点的个数,线的总长度,面的总面积

代码:

import arcpy
aprx = arcpy.mp.ArcGISProject("current")
map = aprx.listMaps ("Map")[0]
layers = map.listLayers()
layersList={}
for layer in layers:
    layercolor={}
    layer_datasorce = layer.dataSource
    describe = arcpy.Describe(layer_datasorce)
    geotype = describe.shapeType
    print("图层的着色器类型:",layer.symbology.renderer.type)
    if layer.symbology.renderer.type == "GraduatedColorsRenderer":
        print("分级色彩分级数:",layer.symbology.renderer.breakCount)
        classificationField=layer.symbology.renderer.classificationField
        print("分级色彩字段:",classificationField)
        GraduatedColorsRendererSumList=[]
        for item in range(int(layer.symbology.renderer.breakCount)):
            GraduatedColorsRendererclassBreaks = layer.symbology.renderer.classBreaks
            GraduatedColorsRendererSumList.append(GraduatedColorsRendererclassBreaks[item].upperBound)
        for index in range(len(GraduatedColorsRendererSumList)):
            layercolor[str(index)]=float(0.0)
        if geotype == "Point":
            sumfields = "OID@"
        elif geotype == "Polyline":
            sumfields = "SHAPE@LENGTH"
        elif geotype == "Polygon":
            sumfields = "SHAPE@AREA"
        with arcpy.da.SearchCursor(layer_datasorce,[classificationField,sumfields]) as cursor:
            for row in cursor:
                currentdata = row[0]
                for index in range(len(GraduatedColorsRendererSumList)):
                    if index == 0:
                        if currentdata >0 and currentdata <= GraduatedColorsRendererSumList[index]:
                            if geotype == "Point":
                                layercolor["0"] = layercolor["0"]+1
                            else:
                                layercolor["0"] = layercolor["0"]+row[1]
                    else:
                        if currentdata >GraduatedColorsRendererSumList[index-1] and currentdata <= GraduatedColorsRendererSumList[index]:
                            if geotype == "Point":
                                layercolor[str(index)] = layercolor[str(index)]+1
                            else:
                                layercolor[str(index)] = layercolor[str(index)]+row[1]
    layersList[layer.name]=layercolor
print(layersList)

结果:

图层的着色器类型: GraduatedColorsRenderer
分级色彩分级数: 10
分级色彩字段: c
图层的着色器类型: GraduatedColorsRenderer
分级色彩分级数: 5
分级色彩字段: SHAPE_Length
{'AANP': {'0': 527, '1': 527, '2': 527, '3': 527, '4': 527, '5': 527, '6': 527, '7': 527, '8': 527, '9': 527}, 'RESA': {'0': 0.13077272805245335, '1': 0.1429921138939844, '2': 0.10898674509959612, '3': 0.08380454923214925, '4': 0.013951557062533943}}

参考文献:

读取几何—ArcGIS Pro | 文档

SearchCursor—ArcGIS Pro | 文档

Symbol—ArcGIS Pro | 文档

Symbology—ArcGIS Pro | 文档

Layer—ArcGIS Pro | 文档

文章来源:https://blog.csdn.net/qq_39397927/article/details/135111402
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。