Select to view content in your preferred language

Create Unique Symbology of Images per Point based off of an attribute field

303
1
12-27-2024 03:06 AM
Labels (1)
SK_bp
by
New Contributor

I have a Point layer in ArcGIS Pro 3.2. The underlying attribute table has a field called ImagePath. In that field are unique UNC paths to images (e.g. *.png etc) that I want to act as the symbol for that point feature on the map.

Currently, I have the following code, partly generated from genAI, but can't figure out how to get this working - if it's at all possible. Does anyone have experience with automating this process as a script in ArcGIS Pro?

 

import arcpy

# Define the project and map
project = arcpy.mp.ArcGISProject("CURRENT")
map = project.listMaps("YourMapName")[0]

# Define the layer
layer = map.listLayers("YourLayerName")[0]

# Create a new unique value renderer
symbology = layer.symbology
symbology.updateRenderer('UniqueValueRenderer')
symbology.renderer.fields = ['ImagePath']

# Clear any existing classes
unique_value_renderer = symbology.renderer
unique_value_renderer.removeAllValues()

# Add a class for each unique value in the ImagePath field
unique_values = set()
with arcpy.da.SearchCursor(layer, ['ImagePath']) as cursor:
    for row in cursor:
        unique_values.add(row[0])

for value in unique_values:
    if value:
        unique_value_renderer.addValue(value, value, value)
        symbol = unique_value_renderer.getSymbol(value)
        picture_marker = arcpy.mp.PictureMarkerSymbol()
        picture_marker.url = value
        symbol.updateSymbol(picture_marker)

# Apply the symbology to the layer
layer.symbology = symbology

# Refresh the active view
arcpy.mp.ArcGISProject("CURRENT").activeView.refresh()
0 Kudos
1 Reply
DanPatterson
MVP Esteemed Contributor

Before you go the coding route, have you managed to set it up properly?

Marker symbol layers—ArcGIS Pro | Documentation

picture symbols are expected to be in a blob field in an attribute table or preferably an attachment table


... sort of retired...