IElement pEle = pLineEle as IElement;

pEle.Geometry = pLn;

pLn为一个ILine对象,想当然的以为它是IGeometry对象,可以赋值,结果爆出异常值不在预期范围内。

解决方法是将ILine转换为IPolyline对象,涉及到一些Geometry的基本操作。贴出一些可用的绘制元素的代码

#region 获取RgbColor
/// <summary>
/// 获取RgbColor颜色对象
/// </summary>
/// <param name="r"></param>
/// <param name="g"></param>
/// <param name="b"></param>
/// <param name="alpa">可选参数,透明度.0代表透明</param>
/// <returns></returns>
public static IRgbColor getRgbColor(int r, int g, int b, byte alpa = 255)
{
IRgbColor pColor = new RgbColorClass();
pColor.Red = r;
pColor.Green = g;
pColor.Blue = b;
pColor.Transparency = alpa; return pColor;
}
#endregion #region 获取随机颜色
/// <summary>
/// 获取随机颜色
/// </summary>
/// <returns></returns>
public static IRgbColor getRandColor()
{
Random rd = new Random();
IRgbColor myColor = new RgbColorClass();
myColor.Red = rd.Next(0, 255);
myColor.Blue = rd.Next(0, 255);
myColor.Green = rd.Next(0, 255); return myColor;
}
#endregion #region 绘制线
/// <summary>
/// 绘制线
/// </summary>
/// <param name="pLine"></param>
/// <param name="pMapCtrl"></param>
/// <param name="pLineSymbol">线符号</param>
/// <param name="refresh">刷新</param>
public static void DrawLine(ILine pLine, IMapControl2 pMapCtrl, ISimpleLineSymbol pLineSymbol
, bool refresh)
{
ILineElement pLineEle = new LineElementClass();
pLineEle.Symbol = pLineSymbol;
IGeometryCollection pPolyline = new PolylineClass();
ISegmentCollection pPath = new PathClass();
object m1 = Type.Missing;
object m2 = Type.Missing;
pPath.AddSegment(pLine as ISegment, ref m1, ref m2);
pPolyline.AddGeometry(pPath as IGeometry, ref m1, ref m2);
IElement pEle = pLineEle as IElement;
pEle.Geometry = pPolyline as IGeometry;
IGraphicsContainer pGC = pMapCtrl.Map as IGraphicsContainer;
pGC.AddElement(pEle, 0);
if (refresh)
{
IActiveView pAv = pMapCtrl.ActiveView;
pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
}
#endregion #region 绘制文字注记
/// <summary>
/// 绘制文字
/// </summary>
/// <param name="pnt"></param>
/// <param name="value"></param>
/// <param name="ptxtSym"></param>
/// <param name="pMapCtrl"></param>
/// <param name="refresh"></param>
public static void DrawTextEle(IPoint pnt, string strvalue, ITextSymbol ptxtSym,
IMapControl2 pMapCtrl, bool refresh)
{
ITextElement pTextEle = new TextElementClass();
pTextEle.Text = strvalue;
pTextEle.Symbol = ptxtSym; IElement pEle = pTextEle as IElement;
pEle.Geometry = pnt;
IGraphicsContainer pGc = pMapCtrl.Map as IGraphicsContainer;
pGc.AddElement(pEle, 0);
if (refresh)
{
IActiveView pAv = pMapCtrl.ActiveView;
pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
}
#endregion #region 绘制polyline
/// <summary>
///
/// </summary>
/// <param name="pPolyline"></param>
/// <param name="pLineSym"></param>
/// <param name="pMapCtrl"></param>
/// <param name="refresh"></param>
public static void DrawPolyline(IPolyline pPolyline, ISimpleLineSymbol pLineSym, IMapControl2 pMapCtrl,
bool refresh)
{
ILineElement pLineEle = new LineElementClass();
IElement pEle = pLineEle as IElement;
pLineEle.Symbol = pLineSym;
pEle.Geometry = pPolyline; IGraphicsContainer pGc = pMapCtrl.Map as IGraphicsContainer;
pGc.AddElement(pEle, 0);
if (refresh)
{
IActiveView pAv = pMapCtrl.ActiveView;
pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
}
#endregion #region 绘制点
/// <summary>
/// 绘制点
/// </summary>
/// <param name="pnt"></param>
/// <param name="pMapCtrl"></param>
/// <param name="pColor">颜色</param>
/// <param name="refresh">是否刷新</param>
public static void DrawPoint(IPoint pnt, IMapControl2 pMapCtrl, IRgbColor pColor, bool refresh)
{
ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbolClass(); pMarkerSymbol.Color = pColor;
pMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
pMarkerSymbol.Size = 3;
IElement pEle;
IMarkerElement pMe = new MarkerElementClass();
pMe.Symbol = pMarkerSymbol;
pEle = pMe as IElement;
pEle.Geometry = pnt; IActiveView pav = pMapCtrl.ActiveView;
IGraphicsContainer pGc = pMapCtrl.Map as IGraphicsContainer;
pGc.AddElement(pEle, 0);
if (refresh)
pav.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
#endregion

ArcEngine开发:IElement.Geometry 值不在预期范围内 + 元素绘制代码的更多相关文章

  1. Arcengine 开发,FeatureClass新增feature时“The Geometry has no z-value”或"The Geometry has null z-value"的解决方案

    Arcengine 开发,当图层含有Z值时,新增的feature没有Z值就会 出现“The Geometry has no z-value”的错误.意思很明显,新增的geometry没有Z值. 此时按 ...

  2. arcengine 开发经典帖

    http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=25575&page=1&extra= 使用ArcGIS Engine 开发自定义 ...

  3. ArcEngine开发中“错误类型"****"未定义构造函数”

    from:http://blog.csdn.net/mengdong_zy/article/details/8990593 问题 在ArcEngine开发的时候,在编译时,发现出现这样的错误,出错的地 ...

  4. ArcEngine创建IElement简单例子

    转自IT-GIS终结者原文ArcEngine创建IElement简单例子 代码下载地址:http://files.cnblogs.com/ogis/MapControlApplication2.rar ...

  5. arcengine 开发经典帖 【强烈推荐仔细研读】

    转自原文 arcengine 开发经典帖 使用ArcGIS Engine 开发自定义GIS应用: 第一部分:使用ArcGIS Engine 发布自定义GIS应用软件-全面了解ArcGIS Engine ...

  6. 利用ArcEngine开发地图发布服务,将mxd文档一键发布成wmts,并根据需要对地图进行空间查询,返回客户端geojson

    一直想开发一个软件取代ArcGIS Server,该软件使用ArcEngine开发,以Windows Service形式发布,部署在服务端上,解决wmts地图服务发布和空间查询的问题,经过不断的研究. ...

  7. Value does not fall within the expected range 值不在预期的范围内

    用vs2012 打开web.config时,提示如下错误:“Value does not fall within the expected range”; 中文提示:“值不在预期的范围内” 解决方案: ...

  8. ArcEngine开发遇到的问题(转)

    ArcEngine开发遇到的问题 https://blog.csdn.net/u013751758/article/category/6971559 转载 2018年02月11日 17:28:11 1 ...

  9. Android Studio获取开发版SHA1值和发布版SHA1值,详细过程

    转自原文 Android Studio获取开发版SHA1值和发布版SHA1值的史上最详细方法 前言: 今天我想把百度地图的定位集成到项目中来,想写个小小的案例,实现一下,但在集成百度地图时首先要申请秘 ...

随机推荐

  1. iOS 中使用Block时需要注意的retain circle

    现在在ios中,block是越来越多了.自己在类中定义block对象时,需要注意block对象的使用方法,防止产生retain circle,导致内存泄露. 现在分析一下产生retain circle ...

  2. php扩展开发初探

    2015年2月26日 15:44:41 原因: 想用PHP实现一个布隆过滤器算法, 其中要用到位运算, 但是PHP的内置的int类型不给力, 不能支持大整数的位运算 数据一旦太大, 就会变为浮点数表示 ...

  3. php开发网站编码统一问题

    一个良好的网站代码整洁,注释适当是最基本的,也是好的习惯,这可以避免以后的非常乱了自己感觉都乱,一旦重构麻烦就大了耗时耗力,其中网站整个体系的编码是最重要的一个方面,为了网站的稳定性建议php程序,H ...

  4. Java for LeetCode 160 Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  5. kail ip配置

    设置ip /etc/network/interfaces # This file describes the network interfaces available on your system # ...

  6. git_2-linux

    在linux下搭建git环境1.创建Github账号,https://github.com2.Linux创建SSH密钥: ssh-keygen  ##一直默认就可以了 3.将公钥加入到Github账户 ...

  7. 搭建邮局(邮件服务器) - hmailserver

    1.查看服务器mx是否解析成功 nslookup  set type=mx   2.hmailserver服务器 smtp设置     3.foxmail 设置   4.使用webmail(after ...

  8. 3.工厂方法模式(Factory Method)

    using System; using System.Reflection; namespace ConsoleApplication1 { class Program { static void M ...

  9. mysql中char,varchar与text类型的区别和选用

    关于char,varchar与text平时没有太在意,一般来说,可能现在大家都是用varchar.但是当要存储的内容比较大时,究竟是选择varchar还是text呢?不知道...... 于是去查阅了一 ...

  10. oracle 10g 学习之多表查询、分组函数(6)

    笛卡尔集 l  笛卡尔集会在下面条件下产生: 省略连接条件 连接条件无效 所有表中的所有行互相连接 l  为了避免笛卡尔集, 可以在 WHERE 加入有效的连接条件. 自连接 select m.las ...