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值的史上最详细方法 前言: 今天我想把百度地图的定位集成到项目中来,想写个小小的案例,实现一下,但在集成百度地图时首先要申请秘 ...
随机推荐
- php-fpm启动
2014年6月30日 11:52:17 遇到一个问题,安装了redis.so后无论怎么重启nginx 还是 php-fpm都无法加载redis 最后发现重启php-fpm的参数弄错了 要这样: ./p ...
- C++多线程下的单例模式
一.懒汉模式:即第一次调用该类实例的时候才产生一个新的该类实例,并在以后仅返回此实例. 需要用锁,来保证其线程安全性:原因:多个线程可能进入判断是否已经存在实例的if语句,从而non thread s ...
- MySQL错误:Every derived table must have its own alias
Every derived table must have its own alias 派生表都必须有自己的别名 一般在多表查询时,会出现此错误. 因为,进行嵌套查询的时候子查询出来的的结果是作为一个 ...
- 联系旭日150安装CentOS5.X版本手记
有一台旧电脑.想装个Linux.于是上网查了查.据说可以装CentOS5.3.于是我就去下载了一个. 下载地址可以到http://www.centoscn.com/去下载. 我先下载的是5.3版本的I ...
- Xamarin.Android开发实践(十四)
Xamarin.Android之ListView和Adapter 一.前言 如今不管任何应用都能够看到列表的存在,而本章我们将学习如何使用Xamarin去实现它,以及如何使用适配器和自定义适配器(本文 ...
- Mongodb安装(Mac平台)
1安装: sudo brew install mongodb 2 启动MongoDb sudo mongod —config /usr/local/etc/mongod.conf 3.登录mongo ...
- loj 1046(bfs)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26766 思路:由于数据不是很大,我们可以枚举骑士最后聚集的位置,然 ...
- hive复杂类型与java类型的对应
因为要往自定义的UDF传入复杂类型,所以需要对于这块的对应简单做一下总结 string java.lang.String, org.apache.hadoop.io.Text int int, jav ...
- poj 1114 完全背包 dp
如果可以每个物品拿多件,则从小到大遍历,否则从大到小遍历. G - Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO ...
- spring获取webapplicationcontext,applicationcontext几种方法详解
法一:在初始化时保存ApplicationContext对象代码: ApplicationContext ac = new FileSystemXmlApplicationContext(" ...