ArcGIS Pro 3.0 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
    public async Task<IList<ColorRampStyleItem>> GetColorRampsFromStyleAsync(StyleProjectItem style, string searchString)
    {
      //StyleProjectItem can be "ColorBrewer Schemes (RGB)", "ArcGIS 2D"...
      if (style == null)
        throw new System.ArgumentNullException();
    
      //Search for color ramps
      //Color Ramp searchString can be "Spectral (7 Classes)", "Pastel 1 (3 Classes)", "Red-Gray (10 Classes)"..
      return await QueuedTask.Run(() => style.SearchColorRamps(searchString));
    }
    How to apply a color ramp from a style to a feature layer
    public async Task ApplyColorRampAsync(FeatureLayer featureLayer, List<string> fields)
    {
    
        StyleProjectItem style =
            Project.Current.GetItems<StyleProjectItem>()
                .FirstOrDefault(s => s.Name == "ColorBrewer Schemes (RGB)");
        if (style == null) return;
        var colorRampList = await QueuedTask.Run(() => 
                    style.SearchColorRamps("Red-Gray (10 Classes)"));
        if (colorRampList == null || colorRampList.Count == 0) return;
        CIMColorRamp cimColorRamp = null;
        CIMRenderer renderer = null;
        await QueuedTask.Run(() =>
        {
            cimColorRamp = colorRampList[0].ColorRamp;
            var rendererDef = new UniqueValueRendererDefinition(fields, null, cimColorRamp);
            renderer = featureLayer?.CreateRenderer(rendererDef);
            featureLayer?.SetRenderer(renderer);
        });
    
    }
    How to apply a color ramp from a style to a feature layer
    public async Task ApplyColorRampAsync(FeatureLayer featureLayer, List<string> fields)
    {
    
        StyleProjectItem style =
            Project.Current.GetItems<StyleProjectItem>()
                .FirstOrDefault(s => s.Name == "ColorBrewer Schemes (RGB)");
        if (style == null) return;
        var colorRampList = await QueuedTask.Run(() => 
                    style.SearchColorRamps("Red-Gray (10 Classes)"));
        if (colorRampList == null || colorRampList.Count == 0) return;
        CIMColorRamp cimColorRamp = null;
        CIMRenderer renderer = null;
        await QueuedTask.Run(() =>
        {
            cimColorRamp = colorRampList[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 style = Project.Current.GetItems<StyleProjectItem>().First(s => s.Name == colorBrewerSchemesName);
    string colorRampName = "Greens (Continuous)";
    IList<ColorRampStyleItem> colorRampList = await QueuedTask.Run(() =>
    {
      return style.SearchColorRamps(colorRampName);
    });
    ColorRampStyleItem colorRamp = colorRampList[0];
    
    await QueuedTask.Run(() =>
    {
      GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition()
      {
        ClassificationField = "CROP_ACR07",
        ClassificationMethod = ArcGIS.Core.CIM.ClassificationMethod.NaturalBreaks,
        BreakCount = 6,
        ColorRamp = colorRamp.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
      };
      LayerFactory.Instance.CreateLayer<FeatureLayer>(featureLayerCreationParams, MapView.Active.Map);
    });
    
    Create and Set a Stretch Renderer
    //Must be called on the MCT
    //var pcsl = ...;
    
    //At 2.x - var fields = pcsl.QueryAvailablePointCloudRendererFields(
    //                           PointCloudRendererType.StretchRenderer);
    
    var fields = pcsl.GetAvailablePointCloudRendererFields(
                             PointCloudRendererType.StretchRenderer);
    var stretchDef = new PointCloudRendererDefinition(
                              PointCloudRendererType.StretchRenderer)
    {
      //Will be either ELEVATION or INTENSITY
      Field = fields[0]
    };
    //Create the CIM Renderer
    var stretchRenderer = pcsl.CreateRenderer(stretchDef) 
                                       as CIMPointCloudStretchRenderer;
    //Apply a color ramp
    var style = Project.Current.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
    pcsl.SetRenderer(stretchRenderer);
    
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also