Layer symbology - adjust to new attribute values

1353
4
Jump to solution
12-05-2017 10:44 PM
RobertFritz2
New Contributor

Hi,

I have got many layers each one with extensive symbology. Now I need to change the data source for these layers. The new data sources have different table names (no problem), different field names (no problem)  and different values. Now I struggle with the values - I thought I could just edit the values and replace them (such as "1" with "510"). But I can't figure out how. Is that possible (ArcMap 10.3)? I don't want to create lookup tables as suggested somewhere else. If I cant change values used in layer symbology in ArcMap - could it be done using ArcPy (yes / no)?

Thanks, Rob

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

If I understand you correctly, you have many layers with different schemas  (fields, etc) but they all have a field that represents the same type of information, however each layer may use it's own values.

Normally you would use domains, but I am sure that this is data provided to you and you have had no influence over the way data is managed. 

In this case I would suggest to work with LUTs (lookup tables) or some source that you can use to interpret a value and assign the correct one. You could use a script that does this for you, but any solution you choose will require you to indicate which value needs to be mapped to the correct value. 

To provide some example of a script that do the mapping between the value, here's an example:

def main():
    import arcpy

    lut = r'C:\some\path\to\yourData.gdb\yourLUT'
    fld_source = 'name of field with source values'
    fld_correct = 'name of field with correct values'

    fc = r'C:\some\path\to\yourData.gdb\yourFeatures'
    fld_input_value = 'your field with wrong values'
    fld_output_value = 'new field to store correct values'

    # create dictionary from LUT
    dct_lut = {r[0]: r[1] for r in arcpy.da.SearchCursor(lut, (fld_source, fld_correct))}

    # add field to output, will overwrite value if output field already exists
    if len(arcpy.ListFields(fc, fld_output_value)) == 0:
        # adjust to type of field
        arcpy.AddField_management(fc, fld_output_value, "SHORT") 

    # update the values using the lut
    fields = (fld_input_value, fld_output_value)
    with arcpy.da.UpdateCursor(fc, flds) as curs:
        for row in curs:
            in_value = row[0]
            if in_value in dct_lut:
                row[1] = dct_lut[in_value]
                curs.updateRow(row)

if __name__ == '__main__':
    main()

 (not tested)

View solution in original post

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

Is it a label or a separate text element?  What are the values you want to convert?  That will determine the approach if any

0 Kudos
RobertFritz2
New Contributor

Hi Dan,

I need to adjust the attribute values used for symbolizing features.

I changed the data source and the field Name (was: symby,  is now: objektart_id).

With the Change in data source the attrbute values ahve changed as well, such as that SYMBY = 1 equals OBJEKTART_ID 510.

So I want to swap the Attribute values but retain the symbolization.

I have many layers each with extensive symbology.

Ideally I could save the layer file as XML and modify the values there but ArcMap doesnt allow this. Is there any other way to achieve this with reasonable effort? ArcPy would be an Option as well.

Screenshot is attached,

Thank you, RobLayer_Properties_Symbology

0 Kudos
XanderBakker
Esri Esteemed Contributor

If I understand you correctly, you have many layers with different schemas  (fields, etc) but they all have a field that represents the same type of information, however each layer may use it's own values.

Normally you would use domains, but I am sure that this is data provided to you and you have had no influence over the way data is managed. 

In this case I would suggest to work with LUTs (lookup tables) or some source that you can use to interpret a value and assign the correct one. You could use a script that does this for you, but any solution you choose will require you to indicate which value needs to be mapped to the correct value. 

To provide some example of a script that do the mapping between the value, here's an example:

def main():
    import arcpy

    lut = r'C:\some\path\to\yourData.gdb\yourLUT'
    fld_source = 'name of field with source values'
    fld_correct = 'name of field with correct values'

    fc = r'C:\some\path\to\yourData.gdb\yourFeatures'
    fld_input_value = 'your field with wrong values'
    fld_output_value = 'new field to store correct values'

    # create dictionary from LUT
    dct_lut = {r[0]: r[1] for r in arcpy.da.SearchCursor(lut, (fld_source, fld_correct))}

    # add field to output, will overwrite value if output field already exists
    if len(arcpy.ListFields(fc, fld_output_value)) == 0:
        # adjust to type of field
        arcpy.AddField_management(fc, fld_output_value, "SHORT") 

    # update the values using the lut
    fields = (fld_input_value, fld_output_value)
    with arcpy.da.UpdateCursor(fc, flds) as curs:
        for row in curs:
            in_value = row[0]
            if in_value in dct_lut:
                row[1] = dct_lut[in_value]
                curs.updateRow(row)

if __name__ == '__main__':
    main()

 (not tested)

0 Kudos
RobertFritz2
New Contributor

Hi Xander,

many thanks. The new data source will be in place for a long time as the data model has been simplified and standardized. Using lookup tables won't solve my problem in the long term. At some point I just need to adapt layer symbology to the new values. 

I assume there is already a feature request in place to be able to modify/change the values in layer symbology? Or maybe thats already possible with ArcGIS Pro (although that wouldn't help me either as I need to publish to MDX to our server). Anyway - looks like I cant do it the way I thought,

Rob

0 Kudos