ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / StyleHelper Class / SearchColorRamps Method
The StyleProjectItem to search.
The search term.
Example

In This Topic
    SearchColorRamps Method
    In This Topic
    Returns a collection of color ramp style items that satisfy the search criteria. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    styleProjectItem
    The StyleProjectItem to search.
    searchString
    The search term.

    Return Value

    A collection of ColorRampStyleItem.
    Exceptions
    ExceptionDescription
    This method must be called within the lambda passed to QueuedTask.Run
    Example
    How to search for color ramps in a style
    {
      //StyleProjectItem can be "ColorBrewer Schemes (RGB)", "ArcGIS 2D"...
      //Search for color ramps
      //Color Ramp searchString can be "Spectral (7 Classes)", "Pastel 1 (3 Classes)", "Red-Gray (10 Classes)"..
      styleProjectItem.SearchColorRamps("searchString");
    }
    How to apply a color ramp from a style to a feature layer
    {
      List<string> fields = new List<string>() { "Field1" };
      var project = Project.Current;
      await QueuedTask.Run(() =>
      {
        StyleProjectItem styleToUse =
          project.GetItems<StyleProjectItem>()
              .FirstOrDefault(s => s.Name == "ColorBrewer Schemes (RGB)");
        if (style == null)
        {
          return;
        }
        var colorRampListFound = styleToUse.SearchColorRamps("Red-Gray (10 Classes)");
        if (colorRampListFound == null || colorRampListFound.Count == 0)
        {
          return;
        }
    
        CIMColorRamp cimColorRamp = null;
        CIMRenderer renderer = null;
    
        cimColorRamp = colorRampListFound[0].ColorRamp;
        var rendererDef = new UniqueValueRendererDefinition(fields, null, cimColorRamp);
        renderer = featureLayer?.CreateRenderer(rendererDef);
        featureLayer?.SetRenderer(renderer);
      });
    }
    Create a feature layer with class breaks renderer
    {
      string colorBrewerSchemesName = "ColorBrewer Schemes (RGB)";
      StyleProjectItem colorBrewerStyle = Project.Current.GetItems<StyleProjectItem>().First(s => s.Name == colorBrewerSchemesName);
      string colorRampName = "Greens (Continuous)";
      IList<ColorRampStyleItem> colorRampListFromTheStyle = await QueuedTask.Run(() =>
        colorBrewerStyle.SearchColorRamps(colorRampName));
    
      ColorRampStyleItem colorRampFound = colorRampList[0];
      GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition()
      {
        ClassificationField = "CROP_ACR07",
        ClassificationMethod = ArcGIS.Core.CIM.ClassificationMethod.NaturalBreaks,
        BreakCount = 6,
        ColorRamp = colorRampFound.ColorRamp,
        SymbolTemplate = SymbolFactory.Instance.ConstructPolygonSymbol(
                                ColorFactory.Instance.GreenRGB, SimpleFillStyle.Solid, null).MakeSymbolReference(),
        ExclusionClause = "CROP_ACR07 = -99",
        ExclusionSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(
                                ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid, null).MakeSymbolReference(),
        ExclusionLabel = "No yield",
      };
      var featureLayerCreationParams = new FeatureLayerCreationParams((new Uri(@"c:\Data\CountyData.gdb\Counties")))
      {
        Name = "Crop",
        RendererDefinition = gcDef
      };
      await QueuedTask.Run(() =>
        LayerFactory.Instance.CreateLayer<FeatureLayer>(featureLayerCreationParams, map));
    }
    Create a new colorizer based on a custom colorizer definition and apply it to the raster layer
    {
      // Check if the Stretch colorizer can be applied to the raster layer.
      //Get a color ramp from a style
      var project = Project.Current;
      StyleProjectItem ArcGISColorsStyleItem =
            project.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS Colors");
      await QueuedTask.Run(async () =>
      {
        var colorRamps = ArcGISColorsStyleItem.SearchColorRamps("Heat Map 4 - Semitransparent");
        CIMColorRamp colorRampToUse = colorRampList[0].ColorRamp;
        if (rasterLayer.GetApplicableColorizers().Contains(RasterColorizerType.StretchColorizer))
        {
          // Create a new Stretch Colorizer Definition specifying parameters
          // for band index, stretch type, gamma and color ramp.
          StretchColorizerDefinition stretchColorizerDef_custom =
            new StretchColorizerDefinition(1, RasterStretchType.ESRI, 2, colorRamp);
          // Create a new stretch colorizer using the colorizer definition created above.
          CIMRasterStretchColorizer newStretchColorizer_custom =
            await rasterLayer.CreateColorizerAsync(stretchColorizerDef_custom) as CIMRasterStretchColorizer;
          // Set the new colorizer on the raster layer.
          rasterLayer.SetColorizer(newStretchColorizer_custom);
        }
      });
    }
    Create and Set a Stretch Renderer
    {
      var currentProject = Project.Current;
      if (currentProject == null)
        return;
    
      await QueuedTask.Run(() =>
      {
        var fields = pointCloudSceneLayer.GetAvailablePointCloudRendererFields(
                                PointCloudRendererType.StretchRenderer);
        var stretchDef = new PointCloudRendererDefinition(
                                  PointCloudRendererType.StretchRenderer)
        {
          //Will be either ELEVATION or INTENSITY
          Field = fields[0]
        };
        //Create the CIM Renderer
        var stretchRenderer = pointCloudSceneLayer.CreateRenderer(stretchDef)
                                            as CIMPointCloudStretchRenderer;
        //Apply a color ramp
        var style = currentProject.GetItems<StyleProjectItem>()
                                        .First(s => s.Name == "ArcGIS Colors");
        var colorRamp = style.SearchColorRamps("").First();
        stretchRenderer.ColorRamp = colorRamp.ColorRamp;
        //Apply modulation
        stretchRenderer.ColorModulation = new CIMColorModulationInfo()
        {
          MinValue = 0,
          MaxValue = 100
        };
        //apply the renderer
        pointCloudSceneLayer.SetRenderer(stretchRenderer);
      });
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also