• AE中的点符号渲染


    窗口设计:

     

    所用到的控件:axSymbolControl、groupBox、MarkerSymbol(Button)、Label、Button、NumericUpDown

    符号窗口代码(记得绑定【确定】【取消】窗口加载等事件):

    public partial class PointSymbol : Form
    
        {
    
            /// <summary>
    
            /// 地图符号对象
    
            /// </summary>
    
            private IMapControlDefault m_mapControl;
    
            private ILayer m_Layer;
    
            private ILegendClass m_LegendClass;
    
            private ISymbologyStyleClass m_SymbologyStyleClass;
    
     
    
            /// <summary>
    
            /// 符号属性集合
    
            /// </summary>
    
            private Dictionary<int, double> sizes;
    
            private Dictionary<int, double> angles;
    
            private Dictionary<int, Color> colors;
    
            public PointSymbol(IMapControlDefault m_mapControl, ILayer m_Layer, ILegendClass m_LegendClass)
    
            {
    
                InitializeComponent();
    
                // 初始化地图符号对象
    
                this.m_mapControl = m_mapControl;
    
                this.m_Layer = m_Layer;
    
                this.m_LegendClass = m_LegendClass;
    
     
    
                // 初始化符号属性集合
    
                this.sizes = new Dictionary<int, double>();
    
                this.angles = new Dictionary<int, double>();
    
                this.colors = new Dictionary<int, Color>();
    
     
    
                // 初始化符号控件
    
                Init();
    
            }
    
            private void Init()
    
            {
    
                axSymbologyControl1.LoadStyleFile(AppDomain.CurrentDomain.BaseDirectory + "ESRI.ServerStyle");
    
                axSymbologyControl1.StyleClass = esriSymbologyStyleClass.esriStyleClassMarkerSymbols;
    
                m_SymbologyStyleClass = axSymbologyControl1.GetStyleClass(axSymbologyControl1.StyleClass);
    
     
    
                // 添加当前符号
    
                IStyleGalleryItem pStyleGalleryItem = new ServerStyleGalleryItem();
    
                pStyleGalleryItem.Name = "当前符号";
    
                pStyleGalleryItem.Item = m_LegendClass.Symbol;
    
                m_SymbologyStyleClass.AddItem(pStyleGalleryItem, 0);
    
     
    
                // 符号属性集合
    
                for (int i = 0; i < m_SymbologyStyleClass.get_ItemCount(); i++)
    
                {
    
                    IStyleGalleryItem item = m_SymbologyStyleClass.GetItem(i);
    
                    IMarkerSymbol pMarkerSymbol = item.Item as IMarkerSymbol;
    
                    if (!sizes.ContainsKey(item.ID))
    
                    {
    
                        sizes.Add(item.ID, pMarkerSymbol.Size);
    
                    }
    
                    if (!angles.ContainsKey(item.ID))
    
                    {
    
                        angles.Add(item.ID, pMarkerSymbol.Angle);
    
                    }
    
                    if (!colors.ContainsKey(item.ID))
    
                    {
    
                        colors.Add(item.ID, ConvertToColor(pMarkerSymbol.Color));
    
                    }
    
                }
    
                m_SymbologyStyleClass.SelectItem(0);
    
            }
    
     
    
            /// <summary>
    
            /// 双击选中符号
    
            /// </summary>
    
            /// <param name="sender"></param>
    
            /// <param name="e"></param>
    
            private void axSymbologyControl1_OnDoubleClick(object sender, ISymbologyControlEvents_OnDoubleClickEvent e)
    
            {
    
                btnOK.PerformClick();
    
            }
    
     
    
            /// <summary>
    
            /// 切换符号
    
            /// </summary>
    
            /// <param name="sender"></param>
    
            /// <param name="e"></param>
    
            private void axSymbologyControl1_OnItemSelected(object sender, ISymbologyControlEvents_OnItemSelectedEvent e)
    
            {
    
                IStyleGalleryItem pStyleGalleryItem = e.styleGalleryItem as IStyleGalleryItem;
    
                numPointSize.Value = (decimal)sizes[pStyleGalleryItem.ID];
    
                numAngle.Value = (decimal)angles[pStyleGalleryItem.ID];
    
                PointColor.BackColor = colors[pStyleGalleryItem.ID];
    
     
    
                // 预览
    
                IMarkerSymbol pMarkerSymbol = pStyleGalleryItem.Item as IMarkerSymbol;
    
                pMarkerSymbol.Size = sizes[pStyleGalleryItem.ID];
    
                pMarkerSymbol.Angle = angles[pStyleGalleryItem.ID];
    
                pMarkerSymbol.Color = ConvertToRgbColor(colors[pStyleGalleryItem.ID]);
    
                PreviewSymbol(pStyleGalleryItem);
    
            }
    
     
    
            /// <summary>
    
            /// 切换颜色
    
            /// </summary>
    
            /// <param name="sender"></param>
    
            /// <param name="e"></param>
    
            private void btnColor_Click(object sender, EventArgs e)
    
            {
    
                ColorDialog colorDialog = new ColorDialog();
    
                if (colorDialog.ShowDialog() == DialogResult.OK)
    
                {
    
                    PointColor.BackColor = colorDialog.Color;
    
     
    
                    // 预览
    
                    IStyleGalleryItem pStyleGalleryItem = m_SymbologyStyleClass.GetSelectedItem();
    
                    IMarkerSymbol pMarkerSymbol = pStyleGalleryItem.Item as IMarkerSymbol;
    
                    pMarkerSymbol.Size = (double)numPointSize.Value;
    
                    pMarkerSymbol.Angle = (double)numAngle.Value;
    
                    pMarkerSymbol.Color = ConvertToRgbColor(PointColor.BackColor);
    
                    PreviewSymbol(pStyleGalleryItem);
    
                }
    
            }
    
     
    
            /// <summary>
    
            /// 切换尺寸
    
            /// </summary>
    
            /// <param name="sender"></param>
    
            /// <param name="e"></param>
    
            private void numPointSize_ValueChanged(object sender, EventArgs e)
    
            {
    
                // 预览
    
                IStyleGalleryItem pStyleGalleryItem = m_SymbologyStyleClass.GetSelectedItem();
    
                IMarkerSymbol pMarkerSymbol = pStyleGalleryItem.Item as IMarkerSymbol;
    
                pMarkerSymbol.Size = (double)numPointSize.Value;
    
                pMarkerSymbol.Angle = (double)numAngle.Value;
    
                pMarkerSymbol.Color = ConvertToRgbColor(PointColor.BackColor);
    
                PreviewSymbol(pStyleGalleryItem);
    
            }
    
     
    
            /// <summary>
    
            /// 切换角度
    
            /// </summary>
    
            /// <param name="sender"></param>
    
            /// <param name="e"></param>
    
            private void numAngle_ValueChanged(object sender, EventArgs e)
    
            {
    
                // 预览
    
                IStyleGalleryItem pStyleGalleryItem = m_SymbologyStyleClass.GetSelectedItem();
    
                IMarkerSymbol pMarkerSymbol = pStyleGalleryItem.Item as IMarkerSymbol;
    
                pMarkerSymbol.Size = (double)numPointSize.Value;
    
                pMarkerSymbol.Angle = (double)numAngle.Value;
    
                pMarkerSymbol.Color = ConvertToRgbColor(PointColor.BackColor);
    
                PreviewSymbol(pStyleGalleryItem);
    
            }
    
     
    
            /// <summary>
    
            /// 确定
    
            /// </summary>
    
            /// <param name="sender"></param>
    
            /// <param name="e"></param>
    
            private void btnOK_Click(object sender, EventArgs e)
    
            {
    
                IGeoFeatureLayer pGeoFeatureLayer = m_Layer as IGeoFeatureLayer;
    
                IFeatureRenderer pFeatureRenderer = pGeoFeatureLayer.Renderer;
    
                ISimpleRenderer pSimpleRenderer = pFeatureRenderer as ISimpleRenderer;
    
                pSimpleRenderer.Symbol = m_SymbologyStyleClass.GetSelectedItem().Item as ISymbol;
    
                m_mapControl.Refresh();
    
                this.Close();
    
            }
    
     
    
            /// <summary>
    
            /// 取消
    
            /// </summary>
    
            /// <param name="sender"></param>
    
            /// <param name="e"></param>
    
            private void btnCancel_Click(object sender, EventArgs e)
    
            {
    
                this.Close();
    
            }
    
     
    
            /// <summary>
    
            /// Color转换为IColor
    
            /// </summary>
    
            /// <param name="color"></param>
    
            /// <returns></returns>
    
            private IColor ConvertToRgbColor(Color color)
    
            {
    
                IColor pColor = new RgbColor();
    
                pColor.RGB = color.R + color.G * 256 + color.B * 65536;
    
                return pColor;
    
            }
    
     
    
            /// <summary>
    
            /// IColor转换为Color
    
            /// </summary>
    
            /// <param name="pColor"></param>
    
            /// <returns></returns>
    
            private Color ConvertToColor(IColor pColor)
    
            {
    
                return ColorTranslator.FromOle(pColor.RGB);
    
            }
    
     
    
            /// <summary>
    
            /// 预览符号
    
            /// </summary>
    
            private void PreviewSymbol(IStyleGalleryItem pStyleGalleryItem)
    
            {
    
                IPictureDisp pPictureDisp = m_SymbologyStyleClass.PreviewItem(pStyleGalleryItem, MarkerSymbol.Width, MarkerSymbol.Height);
    
                Image priviewImage = Image.FromHbitmap(new IntPtr(pPictureDisp.Handle));
    
                MarkerSymbol.Image = priviewImage;
    
            }
    
    }

    系统主窗口代码:(记得绑定TOCControl事件,这里为了测试方便,添加了右键等功能代码)

            private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
    
            {
    
                ESRI.ArcGIS.Controls.esriTOCControlItem Item = ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemNone;
    
                IBasicMap pBasicMap = null;
    
                ILayer pLayer = null;
    
                object other = null;
    
                object index = null;
    
                axTOCControl1.HitTest(e.x, e.y, ref Item, ref pBasicMap, ref pLayer, ref other, ref index);          //实现赋值
    
                //图层左键
    
                if (e.button == 1)
    
                {
    
                    if (Item == esriTOCControlItem.esriTOCControlItemLegendClass)
    
                    {
    
                        if (pLayer is IFeatureLayer)
    
                        {
    
                            IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
    
                            if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
    
                            {
    
                                ILegendGroup pLegendGroup = other as ILegendGroup;
    
                                ILegendClass pLegendClass = pLegendGroup.get_Class((int)index);
    
                                PointSymbol frm = new PointSymbol(axMapControl1.Object as IMapControlDefault, pLayer, pLegendClass);
    
                                frm.ShowDialog();                        }
    
                           
    
                        }
    
                    }
    
                }
    
            }

    运行图:

     

    说明:包括后文中的点符号、面符号(填充符号)都需要此文件:ESRI.ServerStyle。只要装过ArcGIS就会有此文件,可电脑搜索,也可到此链接下载

    https://download.csdn.net/download/say_book/85001155

    也是想出一个系列吧,在自己刚开始学习AE开发的时候苦于查找书籍代码不可用或者各博客描述不够详尽到我一个小白可以读懂,然后踩了各种各样的坑(虽然踩过的坑忘记了很多),其间很多代码的产生都是始于Copy,然后结合自己的查询资料和思考所得,还是希望自己能帮助到各位正在学习或使用的各位同仁吧。

     

    扫码关注公众号

  • 相关阅读:
    【转】Exchange Server 的防火墙开放端口
    【转】AD常用端口
    centos6安装python3
    CMD下的netstat命令
    CMD定时倒数
    【转】netstat 的10个基本用法
    不联网如何PING通WIN主机和VMWARE(懵懂版,不含原理)
    【转载】Putty出现 Network error:Software caused connection abort
    MFC Unicode 字符集下格式转换
    MFC嵌套OpenCV窗口并显示图片
  • 原文地址:https://www.cnblogs.com/pygisxss/p/16041167.html
Copyright © 2020-2023  润新知