转自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, , 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, );
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, );
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, pGeometry.Envelope);
return pElement;
}
else
{
return null;
}
}
catch (Exception ex)
{
return null;
}
}

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}

ArcEngine创建IElement简单例子的更多相关文章

  1. ASP.NET 创建WebService——简单例子

    Web service是一个基于可编程的web的应用程序,用于开发分布式的互操作的应用程序,也是一种web服务 WebService的特性有以下几点: 1.使用XML(标准通用标记语言)来作为数据交互 ...

  2. asp.net mvc项目创建WebApi简单例子

    1.创建默认路由的映射. namespace RedisDemo.App_Start { public class WebApiConfig { public static void Register ...

  3. Hibernate4.2.4入门(一)——环境搭建和简单例子

    一.前言 发下牢骚,这段时间要做项目,又要学框架,搞得都没时间写笔记,但是觉得这知识学过还是要记录下.进入主题了 1.1.Hibernate简介 什么是Hibernate?Hibernate有什么用? ...

  4. 如何创建一个简单的Visual Studio Code扩展

    注:本文提到的代码示例下载地址>How to create a simple extension for VS Code VS Code 是微软推出的一款轻量级的代码编辑器,免费,开源,支持多种 ...

  5. AgileEAS.NET SOA 中间件平台.Net Socket通信框架-简单例子-实现简单的服务端客户端消息应答

    一.AgileEAS.NET SOA中间件Socket/Tcp框架介绍 在文章AgileEAS.NET SOA 中间件平台Socket/Tcp通信框架介绍一文之中我们对AgileEAS.NET SOA ...

  6. 如何创建一个简单的C++同步锁框架(译)

    翻译自codeproject上面的一篇文章,题目是:如何创建一个简单的c++同步锁框架 目录 介绍 背景 临界区 & 互斥 & 信号 临界区 互斥 信号 更多信息 建立锁框架的目的 B ...

  7. mysql定时任务简单例子

    mysql定时任务简单例子 ? 1 2 3 4 5 6 7 8 9     如果要每30秒执行以下语句:   [sql] update userinfo set endtime = now() WHE ...

  8. 最简单例子图解JVM内存分配和回收

    一.简介 JVM采用分代垃圾回收.在JVM的内存空间中把堆空间分为年老代和年轻代.将大量(据说是90%以上)创建了没多久就会消亡的对象存储在年轻代,而年老代中存放生命周期长久的实例对象.年轻代中又被分 ...

  9. CANoe 入门 Step by step系列(三)简单例子的剖析【转】

    最好的学习方式是什么?模仿.有人会问,那不是山寨么?但是我认为,那是模仿的初级阶段,当把别人最好的设计已经融化到自己的血液里,变成自己的东西,而灵活运用的时候,才是真正高级阶段.正所谓画虎画皮难画骨. ...

随机推荐

  1. C#操作SQLite方法实例详解

    用 C# 访问 SQLite 入门(1) CC++C#SQLiteFirefox  用 C# 访问 SQLite 入门 (1) SQLite 在 VS C# 环境下的开发,网上已经有很多教程.我也是从 ...

  2. 【SonicUI】关于字体高亮的问题。。

    m_pSonicString[1]->Format(_T("/c=%x, a='http://hi.csdn.net/', linkh=0xFF00F0, font, font_hei ...

  3. 4lession-输入函数

    接受字符串的方法 #!/usr/bin/python string = raw_input("\nplease inter you string:\n") print(string ...

  4. css中的!important作用

    css中的!important作用 一.总结 1.!important:是hack, 2.!important作用:让浏览器首选执行这个语句,当对同一个对象设置了多个同类型的属性的时候,首选执行这一个 ...

  5. 数据集 —— ground truth 数据集

    1. matlab 自带含 ground truth 数据集 %% 加载停车标志数据到内存: data = load('stopSignsAndCars.mat', 'stopSignsAndCars ...

  6. 10.static_extern

    另一个文件声明 #include <iostream> using namespace std; ; void show() { cout << " << ...

  7. HSV颜色模型

    HSV(Hue, Saturation, Value)是根据颜色的直观特性由A. R. Smith在1978年创建的一种颜色空间, 也称六角锥体模型(Hexcone Model). 注意的是OpenC ...

  8. WCF REST (二)

    今天主要写下  POST等其他方式 发送请求 以及 流方式 文件的上传与下载 一.Post 提交数据 先来想下 POST和Get 的不同   Get 方式 我们直接通过 url  来传递参数   先来 ...

  9. 使用PHP实现双向队列

    使用PHP实现双向队列 一.总结 就是几个array函数 push pop shift unshift n. 移动:变化:手段:轮班 vi. 移动:转变:转换 vt. 转移:改变:替换 二.使用PHP ...

  10. Let's do our own full blown HTTP server with Netty--转载

    原文地址:http://adolgarev.blogspot.com/2013/12/lets-do-our-own-full-blown-http-server.html Sometimes ser ...