唯一值符号化

Style符号库在ArcGIS Engine开发中对应的是ServerStyle符号库,可以通过专门的转换程序把ArcGIS Desktop Style符号库转换为ArcGIS Engine所能够使用的ServerStyle符号库。
用于获取ServerStyle符号库中的符号主要涉及到以下:
接口名称
功能描述
IStyleGallery
用于管理Style Gallery
IStyleGalleryStorage
管理Style Gallery中的符号库文件
IStyleGalleryClass
控制符号库中Style Gallery Class
IEnumStyleGalleryItem
枚举一组Style Gallery items
IStyleGalleryItem
定义Style Galle ry itme

获取ESRI符号库中名称为Rose的符号的流程:
1.首先构建一个ServerStyleGallery对象
2.其次使用IStyleGalleryStorage接口的AddFile方法加载ServerStyle文件
3.遍历ServerGallery中的Class,如果是FillSymbol使用IStyleGallery的GetItems方法返回一个可枚举的包含一系列StyleGalleryItem的EnumStyleGalleryItem对象。
4.遍历EnumServerStyleGalleryItme枚举对象中的StylegalleryItme如果名称是Rose即可获取ESRI符号库中名称为Rose的StylegalleryItme,然后通过IStyleGalleryItem的Item属性即可转换为ISymbol。

///<summary>

///获取符号库中符号

///</summary>

///<param name=”sServerStylePath”>符号库全路径名称</param>

///<param name=”sGalleryClassName”>GalleryClass名称</param>

///<param name=”symbolName”>符号名称</param>

///<returns>符号</returns>

private ISymbol GetSymbol(string sServerStylePath, string sGalleryClassName, string symbolName)

{

    try
    {

    //ServerStyleGallery对象

IStyleGallery pStyleGaller = new ServerStyleGalleryClass();

    IStyleGalleryStorage pStyleGalleryStorage = pStyleGaller as IStyleGalleryStorage;
    IEnumStyleGalleryItem pEnumSyleGalleryItem=null;

    IStyleGalleryItem pStyleGallerItem = null;

    IStyleGalleryClass pStyleGalleryClass = null;

    //使用IStyleGalleryStorage接口的AddFile方法加载ServerStyle文件

pStyleGalleryStorage.AddFile(sServerStylePath);

    //遍历ServerGallery中的Class

    for (int i = 0; i < pStyleGaller.ClassCount; i++)
    {
        pStyleGalleryClass = pStyleGaller.get_Class(i);

        if (pStyleGalleryClass.Name != sGalleryClassName)

            continue;

        //获取EnumStyleGalleryItem对象
pEnumSyleGalleryItem = pStyleGaller.get_Items(sGalleryClassName, sServerStylePath, “”);
        pEnumSyleGalleryItem.Reset();

        //遍历pEnumSyleGalleryItem
        pStyleGallerItem = pEnumSyleGalleryItem.Next();

        while (pStyleGallerItem != null)

        {
            if (pStyleGallerItem.Name == symbolName)
            {

           //获取符号

ISymbol pSymbol = pStyleGallerItem.Item as ISymbol;

           System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumSyleGalleryItem);

           System.Runtime.InteropServices.Marshal.ReleaseComObject(pStyleGalleryClass);

           return pSymbol;

          }

         pStyleGallerItem = pEnumSyleGalleryItem.Next();

       }
   }

  System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumSyleGalleryItem);

  System.Runtime.InteropServices.Marshal.ReleaseComObject(pStyleGalleryClass);

  return null;

}

catch (Exception Err)

{

  MessageBox.Show(Err.Message, “提示”, MessageBoxButtons.OK, MessageBoxIcon.Information);

  return null;

}

}

二、进行唯一值符号化

1.准备点数据,添加属性字段“类别”;
2.并为要素“类别”属性值分别设置为“Hospital2”,“School 1”,“Airport”三种属性值。
3.实现唯一值符号化功能

///<summary>

///设置要素图层唯一值符号化

///</summary>

///<param name=”pFeatureLayer”></param>

private void UniqueValueRenderFlyr(IFeatureLayer pFeatureLayer)

{

  try

  {

  //创建UniqueValueRendererClass对象

IUniqueValueRenderer pUVRender = new UniqueValueRendererClass();

  List<string> pFieldValues= new List<string>();

  pFieldValues.Add(“Hospital 2”);
  pFieldValues.Add(“School 1”);
  pFieldValues.Add(“Airport”);

  for(int i=0;i<pFieldValues.Count;i++)
  {

    ISymbol pSymbol= new SimpleMarkerSymbolClass();
    pSymbol =GetSymbol(@”C:\Program Files\ArcGIS\Styles\ESRI.ServerStyle”,”Marker Symbols”,pFieldValues(i));

    //添加唯一值符号化字段值和相对应的符号
pUVRender.AddValue(pFieldValues,pFieldValues,pSymbol);

  }

//设置唯一值符号化的字段个数和字段名
pUVRender.FieldCount = 1;

  pUVRender.set_Field(0, “类别”);

IGeoFeatureLayer pGFeatureLyr = pFeatureLayer as IGeoFeatureLayer;

  //设置IGeofeatureLayer的Renderer属性
pGFeatureLyr.Renderer = pUVRender as IFeatureRenderer;
  }

catch (Exception Err)
{

  MessageBox.Show(Err.Message, “提示”, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void button1_Click(object sender, EventArgs e)
{

  IFeatureLayer pFeatureLayer = this.axMapControl1.get_Layer(0) as IFeatureLayer;

  UniqueValueRenderFlyr(pFeatureLayer);

  this.axMapControl1.Refresh();

}

转载自:https://blog.csdn.net/lysc_forever/article/details/7768825

You may also like...