• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

gisoracle

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

ArcGIS Pro属性颜色符号化

/// <summary>
/// You must call this method on the MCT!
/// </summary>
/// <returns></returns>
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<CIMUniqueValueClass> classes = new List<CIMUniqueValueClass>();

  //define the unique values for each dicMapUnitColor entry
  foreach (var key in dicMapUnitColor.Keys)
  {
    var lstValue = new List<CIMUniqueValue>()
    {
      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;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

posted on 2022-05-14 21:27  gisai  阅读(259)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3