How do you use the color_ramp raster function on raster's with multiple bands?

525
1
Jump to solution
07-07-2023 02:47 PM
JBuchanan
New Contributor II

I am attempting to apply color ramps to raster files in my project. The stretch renderer allows for applying color ramps to rasters, but currently only has 3 preset options. Alternatively, I have been applying color ramps to my rasters using raster functions. However, I have only been able to load the symbology of a raster layer in runtime if the symbology is RGB. If I configure the symbology as Stretch, Unique Values, Colormap, or Classify, then the layer is loaded into runtime with no symbology, aka the layer is black/white. Raster layers with RGB symbology have multiple bands and my raster functions won't apply to rasters with more than 1 color band.

I am currently using the example color_ramp function format from: Add raster data | ArcGIS Maps SDK for .NET | ArcGIS Developers

 

{
  "raster_function":{"type":"Color_ramp_function"},
  "raster_function_arguments":
  {
    "resizable":{"bool":false,"type":"Raster_function_variable"},
    "color_ramp":
    {
      "color_ramp":
      {
        "ramps":
        [
         {"to_color":[0,255,0],"from_color":[0,191,191],"num_colors":3932,"type":"Algorithmic_color_ramp","algorithmic_type":"hsv"},
         {"to_color":[255,255,0],"from_color":[0,255,0],"num_colors":3932,"type":"Algorithmic_color_ramp","algorithmic_type":"hsv"},
         {"to_color":[255,127,0],"from_color":[255,255,0],"num_colors":3932,"type":"Algorithmic_color_ramp","algorithmic_type":"hsv"},
         {"to_color":[191,127,63],"from_color":[255,127,0],"num_colors":3932,"type":"Algorithmic_color_ramp","algorithmic_type":"hsv"},
         {"to_color":[20,20,20],"from_color":[191,127,63],"num_colors":3935,"type":"Algorithmic_color_ramp","algorithmic_type":"hsv"}
        ],
        "type":"Multipart_color_ramp"
      },
      "type":"Raster_function_variable"
    },
    "raster":{"name":"raster","is_raster":true,"type":"Raster_function_variable"},
    "type":"Raster_function_arguments"
  },
  "type":"Raster_function_template"
}

 


 The issue is that if my raster contains multiple bands, then the raster function throws up an error such as "Band Count is 3."

  • Is there an issue with my raster function?
  • Should I be adding some optional Raster Function Argument to allow for multiband rasters?
  • Are there even other arguments other than "resizable" and "color_ramp"?

My application is offline, so I can't use an image service to handle raster functions.

0 Kudos
1 Solution

Accepted Solutions
DiveshGoyal
Esri Regular Contributor

One approach would be to combine a bunch of raster functions to accomplish this - Extract Band + Color Ramp + Composite Band

Use Extract Band function to create a single raster for each band in your source data
Use Color Ramp function to colorize each single-band raster created above
Use Composite Band function to combine all single-band rasters into a multi-band raster.

See https://developers.arcgis.com/net/layers/add-raster-data/#supported-raster-functions for function syntax

View solution in original post

1 Reply
DiveshGoyal
Esri Regular Contributor

One approach would be to combine a bunch of raster functions to accomplish this - Extract Band + Color Ramp + Composite Band

Use Extract Band function to create a single raster for each band in your source data
Use Color Ramp function to colorize each single-band raster created above
Use Composite Band function to combine all single-band rasters into a multi-band raster.

See https://developers.arcgis.com/net/layers/add-raster-data/#supported-raster-functions for function syntax