Multipart color ramp for script tool raster output symbology with JSON

115
1
Wednesday
jrolson14
New Contributor

Hello, I'm trying to figure out how to properly set up a JSON string to get a multipart color ramp for the output (raster) symbology in a script tool. I've been looking all over the internet but can't find a working example specifically for getting a multipart color ramp. Here's what it looks like:

if __name__ == "__main__":
    in_cdp = arcpy.GetParameterAsText(0)
    in_gdb = arcpy.GetParameterAsText(1)
    in_ocs = arcpy.GetParameterAsText(2)
    in_rff = arcpy.GetParameterAsText(3).split(";")
    in_srr = bool(arcpy.GetParameterAsText(4))
    final_out = arcpy.GetParameterAsText(5)

    main_process(in_cdp, in_gdb, in_ocs, in_rff, in_srr, final_out)

    # Output symbology
    json_str = '''{
        "type": "rasterStretch",
        "colorRamp": {
            "type": "multipart",
            "colorRamps": [
                {
                    "type": "algorithmic",
                    "fromColor": [56, 161, 208, 255],
                    "toColor": [241, 251, 124, 255],
                    "algorithm": "esriHSVAlgorithm"
                },
                {
                    "type": "algorithmic",
                    "fromColor": [241, 251, 124, 255],
                    "toColor": [239, 40, 32, 255],
                    "algorithm": "esriHSVAlgorithm"
                }
            ]
        }
    }'''

    arcpy.SetParameterSymbology(5, f"JSONRENDERER={json_str}")

I've tried tweaking lots of things but every time I just still get the default black to white color ramp. I'm trying to mimic the "Prediction" color ramp available in the symbology pane when you set the symbology manually.

Here's how my parameter set up looks (only including the output's parameter for simplicity):

LabelNameData TypeTypeDirectionDescriptionCategoryFilterDependencyDefaultEnvironmentSymbology
Final OutputfinalRaster DatasetRequiredOutput       

Anyone know what I'm doing wrong?

0 Kudos
1 Reply
HaydenWelch
MVP Regular Contributor

I think it's a formatting thing, Have you tried creating the symbology then saving it as a lyrx? You can either pass the path to that layer file as the symbology source, or copy and paste the parts you want into the json_str variable. The types key should be something like `CIMRaster...`

0 Kudos