1

I have a map I am making where all I want to do is change the source layer for a raster to a new layer. I would then like to apply the same symbology as the original layer, but change the min and max values used to stretch the raster.

So far I have done this:

import arcpy

#load in aprx
aprx = arcpy.mp.ArcGISProject("in_aprx")

#get the maps
one = aprx.listMaps()[0]

#update the current raster with a new raster, this new raster has different min and max values which is what I ultimately want to change

one.updateConnectionProperties(original_layer, new_layer)

#save a copy 
aprx.saveACopy("new_map.aprx")

I can access the layers symbology like so:

one_layers = one.listLayers()

one_layers[0].symbology

but I am not sure how to change the min and max values from here. As of now the minimum and maximum are being used from original_layer which are very different and results in poor stretching.

1 Answer 1

0

The python Cartographic Information Model (CIM) can recalculate stats from an histogram using Arcpy on ArcGIS Pro 2.8:

import arcpy

#ArcGIS Pro workspace to be modified
aprx = arcpy.mp.ArcGISProject("ArcGISProject_URI_Path")
for m in aprx.listMaps():
    ll = m.listLayers()
    for lyr in ll:
        ln = lyr.name
        # Return the layer's CIM definition
        cim_lyr = lyr.getDefinition('V2')
        #Calculate new stats from histogram
        symb = cim_lyr.colorizer
        symb.statsHistogram(ln)
        #Update header CIM object
        lyr.setDefinition(cim_lyr)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.