ArcEngine开发:IElement.Geometry 值不在预期范围内 + 元素绘制代码
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 值不在预期范围内 + 元素绘制代码的更多相关文章
- 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值. 此时按 ...
- arcengine 开发经典帖
http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=25575&page=1&extra= 使用ArcGIS Engine 开发自定义 ...
- ArcEngine开发中“错误类型"****"未定义构造函数”
from:http://blog.csdn.net/mengdong_zy/article/details/8990593 问题 在ArcEngine开发的时候,在编译时,发现出现这样的错误,出错的地 ...
- ArcEngine创建IElement简单例子
转自IT-GIS终结者原文ArcEngine创建IElement简单例子 代码下载地址:http://files.cnblogs.com/ogis/MapControlApplication2.rar ...
- arcengine 开发经典帖 【强烈推荐仔细研读】
转自原文 arcengine 开发经典帖 使用ArcGIS Engine 开发自定义GIS应用: 第一部分:使用ArcGIS Engine 发布自定义GIS应用软件-全面了解ArcGIS Engine ...
- 利用ArcEngine开发地图发布服务,将mxd文档一键发布成wmts,并根据需要对地图进行空间查询,返回客户端geojson
一直想开发一个软件取代ArcGIS Server,该软件使用ArcEngine开发,以Windows Service形式发布,部署在服务端上,解决wmts地图服务发布和空间查询的问题,经过不断的研究. ...
- Value does not fall within the expected range 值不在预期的范围内
用vs2012 打开web.config时,提示如下错误:“Value does not fall within the expected range”; 中文提示:“值不在预期的范围内” 解决方案: ...
- ArcEngine开发遇到的问题(转)
ArcEngine开发遇到的问题 https://blog.csdn.net/u013751758/article/category/6971559 转载 2018年02月11日 17:28:11 1 ...
- Android Studio获取开发版SHA1值和发布版SHA1值,详细过程
转自原文 Android Studio获取开发版SHA1值和发布版SHA1值的史上最详细方法 前言: 今天我想把百度地图的定位集成到项目中来,想写个小小的案例,实现一下,但在集成百度地图时首先要申请秘 ...
随机推荐
- eclipse workspace 共享配置文件
eclipse workspace 共享设置 配置文件记录了原来工程的使用习惯,如字体.编码格式等等,通过拷贝替换达到共享配置的目的. 总结一下,复制工作空间配置步骤如下: 1 使用eclipse新建 ...
- javascript动态添加一组input
2013年12月18日 20:56:29 场景: 批量添加 友情链接 功能 每个友情链接记录有3个字段:名字(name),超链接(url),排序(order) 要求每次点击"添加" ...
- block引发的陷阱
block在项目的开发中使用时非常频繁的,苹果官方也极力推荐使用block.其实,究其本质,block就是指向结构体的指针(可利用运行时机制查看底层生成的c代码).然而在使用block时会存在很多陷阱 ...
- SQL 删除存在于A表但是不存在B表中的记录
目的是是的A表和B表某一个列集合相等 delete from A where tagetColumn not in ( select targetColumn from B)
- CSS对字体单位的总结
国内的设计师大都喜欢用px,而国外的网站大都喜欢用em和rem,那么三者有什么区别,又各自有什么优劣呢? PX特点 1. IE无法调整那些使用px作为单位的字体大小: 2. 国外的大部分网站能够调整的 ...
- Spell checker(poj 1035)
题意: 此题是一个字符串的问题,首先要给出一个字典,里面存储了数个单词.而后,给出一个单词,如果字典中存在,那么就输出correct,如果字典中没有,那么就要判断是不是这个单词有错误,错误有3 ...
- jQuery工具函数
要点:1.字符串操作2.数组和对象操作3.测试操作4.URL 操作5.浏览器检测6.其他操作 工具函数是指直接依附于 jQuery 对象,针对 jQuery 对象本身定义的方法,即全局性的函数.它的作 ...
- SRAM的读写操作
自己写的SRAM的程序,主要在于实用性,适应工作的工程需要.使用芯片为: 芯片时序图为: 代码: /********************************Copyright********* ...
- 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem C: The Trip(水题)
Problem C: The Trip Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 19 Solved: 3[Submit][Status][Web ...
- wp8 导航方法
全局跳转 (App.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Tools/SpatialQueryCha ...