首页 > 其他分享 >ArcGIS Pro二次开发 把图层转成符号库

ArcGIS Pro二次开发 把图层转成符号库

时间:2023-02-17 12:12:40浏览次数:46  
标签:itemType Pro var symbols ArcGIS key 二次开发 symbol StyleItemType

QueuedTask.Run(() => {
   //make some (custom) symbols
   var symbols = new List<CIMSymbol>();
      symbols.Add(SymbolFactory.Instance.DefaultPointSymbol);
      symbols.Add(SymbolFactory.Instance.DefaultLineSymbol);
      symbols.Add(SymbolFactory.Instance.DefaultPolygonSymbol);
      symbols.Add(SymbolFactory.Instance.DefaultTextSymbol);
//access the style file to be updated
var stylx_file = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(
      item => item.Name == "My_Defaults");//must already be in the project
//make the style items that wrap the symbols
  int p = 1;
  int l = 1;
  int pl = 1;
  int t = 1;
  foreach (var symbol in symbols) {
        var key = "";
        var category = "";
        var itemType = StyleItemType.Unknown;

        if (symbol is CIMPointSymbol ptSym) {
          key = $"Point Symbol {p++}";
          category = "Point";
          itemType = StyleItemType.PointSymbol;
        }
        else if (symbol is CIMLineSymbol lnSym){
          key = $"Line Symbol {l++}";
          category = "Line";
          itemType = StyleItemType.LineSymbol;
        }
        else if (symbol is CIMPolygonSymbol polySym) {
          key = $"Polygon Symbol {pl++}";
          category = "Polygon";
          itemType = StyleItemType.PolygonSymbol;
        }
        else if (symbol is CIMTextSymbol textSym) {
          key = $"Text Symbol {t++}";
          category = "Text";
          itemType = StyleItemType.TextSymbol;
        }
        else {
          continue;//mesh
         }
   //make the symbol style item
   var ssi = new SymbolStyleItem() {
     Name = key,//Can be any string - localized is fine
     Key = key,//must be unique
     Tags = itemType.ToString(),//tag1;tag2;tag3;etc
     Category = category,//arbitrary string for organizing your items
     ItemType = itemType,//style item type
     Symbol = symbol //your symbol
  };
   //add the style item
   stylx_file.AddItem(ssi);
  }

  //copy an existing symbol into the style file
  var arcgis_2d = Project.Current.GetItems<StyleProjectItem().FirstOrDefault(
               item => item.Name == "ArcGIS 2D");
  //get an arbitrary symbol, or symbols
  var poly_ssi1 = arcgis_2d.SearchSymbols(StyleItemType.PolygonSymbol, "Glacier")[0];
  var poly_ssi2 = arcgis_2d.SearchSymbols(StyleItemType.PolygonSymbol, "Buffered Gradient")[0];
  //add them
  stylx_file.AddItem(poly_ssi1);
  stylx_file.AddItem(poly_ssi2);
  //... etc ...
});

 

标签:itemType,Pro,var,symbols,ArcGIS,key,二次开发,symbol,StyleItemType
From: https://www.cnblogs.com/gisoracle/p/17129707.html

相关文章