博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ArcEngine创建IElement简单例子
阅读量:4978 次
发布时间:2019-06-12

本文共 8940 字,大约阅读时间需要 29 分钟。

转自原文

代码下载地址:

 

以下几个函数功能主要是向地图中添加IElement,一共四个函数:

GetColor,CreateSimpleLineSymbol,CreateSimpleFillSymbol,AddCreateElement

功能函数:AddCreateElement

调用例子:

ISymbol pSymbol = AEUtil.CreateSimpleFillSymbol(Color.Red, 100, esriSimpleFillStyle.esriSFSCross);

AEUtil.AddCreateElement(pFeature.ShapeCopy,   m_MapControl.ActiveView, pSymbol, fucosKey);
      

通过red green blue 三色创建IRgbColor

public static IRgbColor GetColor(int r, int g, int b){    RgbColor color = new RgbColor();    color.Red = r;    color.Green = g;    color.Blue = b;    return color;}

 

创建简单线Symbol  

 

输入参数 color-颜色,width-宽度,style-线型,有七种线型可选

esriSLSSolid  

  esriSLSDash  
  esriSLSDot 
  esriSLSDashDot 
  esriSLSDashDotDot  
  esriSLSNull  
  esriSLSInsideFrame

public static ISymbol CreateSimpleLineSymbol(Color color, int width, esriSimpleLineStyle style){    ISimpleLineSymbol pSimpleLineSymbol;    pSimpleLineSymbol = new SimpleLineSymbol();    pSimpleLineSymbol.Width = width;    pSimpleLineSymbol.Color = GetColor(color.R, color.G, color.B);    pSimpleLineSymbol.Style = style;    return (ISymbol)pSimpleLineSymbol;}

 

创建面填充ISymbol对象.   

fillColor-颜色,oLineWidth-外廓线宽,fillStyle-填充类型,有以下可选

esriSFSSolid esriSFSNull  esriSFSHollow esriSFSHorizontal esriSFSVertical esriSFSForwardDiagonal esriSFSBackwardDiagonalesriSFSCrossesriSFSDiagonalCross  public static ISymbol CreateSimpleFillSymbol(Color fillColor, int oLineWidth, esriSimpleFillStyle fillStyle){    ISimpleFillSymbol pSimpleFillSymbol;    pSimpleFillSymbol = new SimpleFillSymbol();    pSimpleFillSymbol.Style = fillStyle;    pSimpleFillSymbol.Color = GetColor(fillColor.R, fillColor.G, fillColor.B);    pSimpleFillSymbol.Outline = (ILineSymbol)CreateSimpleLineSymbol(fillColor, 1, esriSimpleLineStyle.esriSLSDash);    return (ISymbol)pSimpleFillSymbol;} // 函数实现向地图中添加元素,pGeometry-元素形状,pActiveView-地图视图,pSymbol-符号,key-元素属性public static IElement AddCreateElement(IGeometry pGeometry, IActiveView pActiveView, ISymbol pSymbol, string key){    try    {        IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer;        IElement pElement = null;        ILineElement pLineElement = null;        IFillShapeElement pFillShapeElement = null;        IMarkerElement pMarkerElement = null;        ICircleElement pCircleElement = null;        IElementProperties pElmentProperties = null;        switch (pGeometry.GeometryType)        {            case esriGeometryType.esriGeometryEnvelope:                {                    pElement = new RectangleElement();                    pElement.Geometry = pGeometry;                    pFillShapeElement = (IFillShapeElement)pElement;                    pFillShapeElement.Symbol = (IFillSymbol)pSymbol;                    break;                }            case esriGeometryType.esriGeometryPolyline:                {                    pElement = new LineElement();                    pElement.Geometry = pGeometry;                    pLineElement = (ILineElement)pElement;                    pLineElement.Symbol = (ILineSymbol)pSymbol;                    break;                }            case esriGeometryType.esriGeometryLine:                {                    pElement = new LineElement();                    pElement.Geometry = pGeometry;                    pLineElement = (ILineElement)pElement;                    pLineElement.Symbol = (ILineSymbol)pSymbol;                    break;                }            case esriGeometryType.esriGeometryPolygon:                {                    pElement = new PolygonElement();                    pElement.Geometry = pGeometry;                    pFillShapeElement = (IFillShapeElement)pElement;                    pFillShapeElement.Symbol = (IFillSymbol)pSymbol;                    break;                }            case esriGeometryType.esriGeometryMultipoint:            case esriGeometryType.esriGeometryPoint:                {                    pElement = new MarkerElement();                    pElement.Geometry = pGeometry;                    pMarkerElement = (IMarkerElement)pElement;                    pMarkerElement.Symbol = (IMarkerSymbol)pSymbol;                    break;                }            case esriGeometryType.esriGeometryCircularArc:                {                    pElement = new CircleElementClass();                    pElement.Geometry = pGeometry;                    pCircleElement = (ICircleElement)pElement;                    break;                }            default:                pElement = null;                break;        }        if (pElement != null)        {            pElmentProperties = pElement as IElementProperties;            pElmentProperties.Name = key;            pGraphicsContainer.AddElement(pElement, 0);            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, pGeometry.Envelope);            return pElement;        }        else        {            return null;        }    }    catch (Exception ex)    {        return null;    }}

 

 

esriSFSSolid

esriSFSNull 

esriSFSHollow

esriSFSHorizontal

esriSFSVertical

esriSFSForwardDiagonal

esriSFSBackwardDiagonal

esriSFSCross

esriSFSDiagonalCross

 

 

 

 

 

 

public static ISymbol CreateSimpleFillSymbol(Color fillColor, int oLineWidth, esriSimpleFillStyle fillStyle)

{

    ISimpleFillSymbol pSimpleFillSymbol;

    pSimpleFillSymbol = new SimpleFillSymbol();

    pSimpleFillSymbol.Style = fillStyle;

    pSimpleFillSymbol.Color = GetColor(fillColor.R, fillColor.G, fillColor.B);

    pSimpleFillSymbol.Outline = (ILineSymbol)CreateSimpleLineSymbol(fillColor, 1, esriSimpleLineStyle.esriSLSDash);

    return (ISymbol)pSimpleFillSymbol;

 

}

 

 

函数实现向地图中添加元素,pGeometry-元素形状,pActiveView-地图视图,pSymbol-符号,key-元素属性

public static IRgbColor GetColor(int r, int g, int b){    RgbColor color = new RgbColor();    color.Red = r;    color.Green = g;    color.Blue = b;    return color;} public static IElement AddCreateElement(IGeometry pGeometry, IActiveView pActiveView, ISymbol pSymbol, string key){    try    {        IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer;        IElement pElement = null;        ILineElement pLineElement = null;        IFillShapeElement pFillShapeElement = null;        IMarkerElement pMarkerElement = null;        ICircleElement pCircleElement = null;        IElementProperties pElmentProperties = null;        switch (pGeometry.GeometryType)        {             case esriGeometryType.esriGeometryEnvelope:                {                    pElement = new RectangleElement();                    pElement.Geometry = pGeometry;                    pFillShapeElement = (IFillShapeElement)pElement;                    pFillShapeElement.Symbol = (IFillSymbol)pSymbol;                    break;                }            case esriGeometryType.esriGeometryPolyline:                {                    pElement = new LineElement();                    pElement.Geometry = pGeometry;                     pLineElement = (ILineElement)pElement;                    pLineElement.Symbol = (ILineSymbol)pSymbol;                    break;                }            case esriGeometryType.esriGeometryLine:                {                    pElement = new LineElement();                    pElement.Geometry = pGeometry;                     pLineElement = (ILineElement)pElement;                    pLineElement.Symbol = (ILineSymbol)pSymbol;                    break;                }            case esriGeometryType.esriGeometryPolygon:                {                    pElement = new PolygonElement();                    pElement.Geometry = pGeometry;                    pFillShapeElement = (IFillShapeElement)pElement;                     pFillShapeElement.Symbol = (IFillSymbol)pSymbol;                    break;                }            case esriGeometryType.esriGeometryMultipoint:            case esriGeometryType.esriGeometryPoint:                {                    pElement = new MarkerElement();                    pElement.Geometry = pGeometry;                     pMarkerElement = (IMarkerElement)pElement;                     pMarkerElement.Symbol = (IMarkerSymbol)pSymbol;                    break;                }            case esriGeometryType.esriGeometryCircularArc:                {                    pElement = new CircleElementClass();                    pElement.Geometry = pGeometry;                     pCircleElement = (ICircleElement)pElement;                    break;                }            default:                pElement = null;                break;        }         if (pElement != null)        {            pElmentProperties = pElement as IElementProperties;            pElmentProperties.Name = key;             pGraphicsContainer.AddElement(pElement, 0);            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, pGeometry.Envelope);            return pElement;        }        else        {            return null;        }    }    catch (Exception ex)    {        return null;    }}

 

 

 

转载于:https://www.cnblogs.com/arxive/p/6262724.html

你可能感兴趣的文章
冒泡排序--c#
查看>>
Wi-Fi与WAPI主要区别
查看>>
Git详解之六:Git工具
查看>>
一个好用的PHOTOSHOP切图插件(CutterMan插件下载)
查看>>
android 引入开源项目
查看>>
《Flask Web开发——基于Python的Web应用开发实践》一字一句上机实践(下)
查看>>
js 自定义方法 设置可选参数的方法
查看>>
Oracle分页查询
查看>>
Python + 装饰器 + @
查看>>
FormsAuthentication.RedirectFromLoginPage 登录
查看>>
2012.05.16
查看>>
前端自动化测试之UI RECORDER(二、PC录制)
查看>>
Linq基本查询操作--帅选
查看>>
hdu 3496 二维费用的01背包
查看>>
poj 3159 差分约束+spfa
查看>>
Linux(Ubuntu)使用日记------tenserflow安装(pip安装法)
查看>>
《Linux权威指南》阅读笔记(2)
查看>>
高精度减法
查看>>
index unusable
查看>>
HDU 6153 A Secret
查看>>