ArcEngine创建IElement简单例子

简介:

转自IT-GIS终结者原文ArcEngine创建IElement简单例子  

代码下载地址:http://files.cnblogs.com/ogis/MapControlApplication2.rar

 

以下几个函数功能主要是向地图中添加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 
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 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;
    }
}
复制代码

 

 

 

没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。





    本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/6262724.html ,如需转载请自行联系原作者

相关文章
|
开发框架 BI C#
C#之二十三 打印和水晶报表
C#之二十三 打印和水晶报表
107 0
|
XML 编解码 API
什么是 SVG?本项目简单分享动画入门的相关知识,并附有相关代码演示,同时文档对SVG等相关内容有比较详细的叙述,如vector标签中属性所代表的意义解释、path标签所支持的指令解释等等。
什么是 SVG?本项目简单分享动画入门的相关知识,并附有相关代码演示,同时文档对SVG等相关内容有比较详细的叙述,如vector标签中属性所代表的意义解释、path标签所支持的指令解释等等。
124 0
什么是 SVG?本项目简单分享动画入门的相关知识,并附有相关代码演示,同时文档对SVG等相关内容有比较详细的叙述,如vector标签中属性所代表的意义解释、path标签所支持的指令解释等等。
|
编解码 C#
基于C#的ArcEngine二次开发教程(17):获取栅格属性的接口及代码实现
基于C#的ArcEngine二次开发教程(17):获取栅格属性的接口及代码实现
基于C#的ArcEngine二次开发教程(17):获取栅格属性的接口及代码实现
语法着色控件使用典型范例
语法着色控件使用典型范例
82 0
|
Java
全网首发:JDK绘制文字:三、绘制句柄的内容是如何定义的
全网首发:JDK绘制文字:三、绘制句柄的内容是如何定义的
99 0
|
存储 定位技术 容器