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值的史上最详细方法 前言: 今天我想把百度地图的定位集成到项目中来,想写个小小的案例,实现一下,但在集成百度地图时首先要申请秘 ...
随机推荐
- Object-c 控制语句
控制语句: 分支语句 if-else 有控制机制 switch 循环语句 while do-while for 跳转语句 break,continue,goto
- CocoaPods 使用本地代码
CocoaPods使用方法 http://iiiyu.com/2013/12/19/learning-ios-notes-thirty-one/ 使用本地方代码的方法如下,下面建立一个名为downlo ...
- php-fpm启动
2014年6月30日 11:52:17 遇到一个问题,安装了redis.so后无论怎么重启nginx 还是 php-fpm都无法加载redis 最后发现重启php-fpm的参数弄错了 要这样: ./p ...
- Java for LeetCode 188 Best Time to Buy and Sell Stock IV【HARD】
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- 6.python模块(导入,内置,自定义,开源)
一.模块 1.模块简介 模块是一个包含所有你定义的函数和变量的文件,其后缀名是.py.模块可以被别的程序引入,以使用该模块中的函数等功能.这也是使用python标准库的方法. 类似于函数式编程和面向过 ...
- plsql查询数据显示为乱码解决方法
使用plsql查询数据显示为乱码: 查看数据库编码: 通过网上搜索,发现需要设置环境变量,添加以下环境变量: LANG=zh_CN.GBK NLS_LANG="SIMPLIFIED CHIN ...
- Session的使用(登录例案+其它页面访问)
本程序功能是使用Session将用户输入的用户名保存在Session中(登录成功情况下,登录失败不会有Session值),其它页面想访问时会先判断是否有之前存的Session值. 登录Login.ht ...
- 关于printf函数输出先后顺序的讲解!!
对于printf函数printf("%d%d\n",a,b);函数的实际输出顺序是这样的先计算出b,然后在计算a,接着输出a,最后在输出b:例子如下:#include<ios ...
- vector data() [c++11]
Example 12345678910111213141516171819202122 // vector::data #include <iostream> #include <v ...
- Andoird自定义ViewGroup实现竖向引导界面
一般进入APP都有欢迎界面,基本都是水平滚动的,今天和大家分享一个垂直滚动的例子. 先来看看效果把: 首先是布局文件: <com.example.verticallinearlayout.Ver ...