计算分级色彩后,各个级别中点的个数,线的总长度,面的总面积
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}}