Add check for duplicate fields for labels and headings

This commit is contained in:
Fuhrmann 2024-12-17 09:34:02 +01:00
parent ff8c99cd8d
commit 6c5f9a6ca0

View file

@ -2,6 +2,7 @@
import arcpy # type: ignore import arcpy # type: ignore
# Define constants
DEFAULT_LINE_WIDTH = 0.7 DEFAULT_LINE_WIDTH = 0.7
DEFAULT_COLOR = [ DEFAULT_COLOR = [
0, 0,
@ -264,7 +265,7 @@ class FeatureRenderer:
layers_to_render = [] layers_to_render = []
for input_layer in input_layers_list: for input_layer in input_layers_list:
present = False present = False
# Test if layer is a group layer and extract layer name from path # Test if layer is a group layer and extract layer name from path
if "\\" in input_layer: if "\\" in input_layer:
input_layer = input_layer.split("\\")[-1] input_layer = input_layer.split("\\")[-1]
@ -310,32 +311,42 @@ class FeatureRenderer:
# Retrieve label texts for custom labels # Retrieve label texts for custom labels
add_labels = False add_labels = False
custom_labels = {}
if label_field_1 or label_field_2: if label_field_1 or label_field_2:
add_labels = True add_labels = True
custom_labels = {} fields = [primary_key_field]
labels = [primary_key_field] if label_field_1 and label_field_1 not in fields:
if label_field_1: fields.append(label_field_1)
labels.append(label_field_1) if label_field_2 and label_field_2 not in fields:
if label_field_2: fields.append(label_field_2)
labels.append(label_field_2)
with arcpy.da.SearchCursor( with arcpy.da.SearchCursor(
table, table,
labels, fields,
) as search_cursor: ) as search_cursor:
for row in search_cursor: for row in search_cursor:
custom_labels[row[0]] = f"{row[1]}{label_delimieter}{row[2]}" if len(fields) == 3:
custom_labels[row[0]] = f"{row[1]}{label_delimieter}{row[2]}"
elif len(fields) == 2:
custom_labels[row[0]] = f"{row[1]}"
elif len(fields) == 1:
custom_labels[row[0]] = f"{row[0]}"
# Retrieve headings # Retrieve headings
headings = {} headings = {}
if heading_field: if heading_field:
labels = [primary_key_field, heading_field] fields = [primary_key_field]
if heading_field not in fields:
fields.append(heading_field)
with arcpy.da.SearchCursor( with arcpy.da.SearchCursor(
table, table,
labels, fields,
) as search_cursor: ) as search_cursor:
for row in search_cursor: for row in search_cursor:
headings[str(row[0])] = row[1] if len(fields) == 2:
headings[str(row[0])] = row[1]
elif len(fields) == 1:
headings[str(row[0])] = row[0]
# Retrieve outline color codes # Retrieve outline color codes
outline_codes = {} outline_codes = {}