ArcGIS Pro属性颜色符号化

///
/// You must call this method on the MCT!

///
///
private CIMRenderer CreateUniqueValueRendererUsingColorTable(FeatureLayer lyrToColor,
  StandaloneTable colorTable)
{
  //All of these methods have to be called on the MCT
  if (OnUIThread)
    throw new ArcGIS.Core.CalledOnWrongThreadException();

  //make a dictionary with MapUnit and Color
  var dicMapUnitColor = new Dictionary<int, string>();
  using (var rowCursor = colorTable.Search())
  {
    while (rowCursor.MoveNext())
    {
      using (var anyRow = rowCursor.Current)
      {
        dicMapUnitColor.Add((int)anyRow["MapUnit"], anyRow["Color"].ToString());
      }
    }
  }

  //Create the Unique Value Renderer
  CIMUniqueValueRenderer uniqueValueRenderer = new CIMUniqueValueRenderer()
  {
    // set the value field
    Fields = new string[] { "MapUnit" }
  };

  //Construct the list of UniqueValueClasses
  List classes = new List();

  //define the unique values for each dicMapUnitColor entry
  foreach (var key in dicMapUnitColor.Keys)
  {
    var lstValue = new List()
    {
      new CIMUniqueValue()
        {
          FieldValues = new string[] { key.ToString() }
        }
    };
    var namedColor = System.Drawing.Color.FromName(dicMapUnitColor[key]);
    var theColor = CIMColor.CreateRGBColor(namedColor.R, namedColor.G, namedColor.B);
    classes.Add(
      new CIMUniqueValueClass()
        {
          Values = lstValue.ToArray(),
          Label = $@"Color: {dicMapUnitColor[key]}",
          Visible = true,
          Editable = true,
          Symbol = new CIMSymbolReference() {
            Symbol = SymbolFactory.Instance.ConstructPointSymbol(
              SymbolFactory.Instance.ConstructMarker(theColor, 20, SimpleMarkerStyle.Pushpin)) }
        }
      );
  }

  //Add the classes to a group (by default there is only one group or "symbol level")
  // Unique value groups
  CIMUniqueValueGroup groupOne = new CIMUniqueValueGroup()
  {
    Heading = "By Color",
    Classes = classes.ToArray()
  };
  uniqueValueRenderer.Groups = new CIMUniqueValueGroup[] { groupOne };

  //Draw the rest with the default symbol
  uniqueValueRenderer.UseDefaultSymbol = true;
  uniqueValueRenderer.DefaultLabel = "All other values";

  var defaultColor = CIMColor.CreateRGBColor(215, 215, 215);
  uniqueValueRenderer.DefaultSymbol = new CIMSymbolReference()
  {
    Symbol = SymbolFactory.Instance.ConstructPointSymbol(
              SymbolFactory.Instance.ConstructMarker(defaultColor, 15, SimpleMarkerStyle.Diamond))
  };

  return uniqueValueRenderer as CIMRenderer;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Original: https://www.cnblogs.com/gisoracle/p/16271588.html
Author: gisoracle
Title: ArcGIS Pro属性颜色符号化

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/545608/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球