前两天好不容易搞好了Map与Scene的二三维联动,以为将二维中的线连动到三维中变成3D样式的管子很简单,又卡了。再一次狂乱的在Esri论坛上找答案,有这样的贴子提到如果用SceneControl加载一个sxd文件,然后在上面画线是可以的,便是如何才能让加载shp文件的SceneControl也能画线呢,有很多人都碰到过这个问题。上面有一个贴子结贴后最佳答案是这样说的:
直接 IGraphicsContainer3D gc3d = new GraphicsLayer3DClass(); 在gc3d上画就OK了。
但是说实话,对于新手的我,我真不知道看了这句话,我应该么样去改我的代码。下面贴出摘自网上的一段在SceneControl控件上监听mouseDown事件连续画线的代码,我在这上面纠结了很久。
private void axSceneControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ISceneControlEvents_OnMouseDownEvent e)
{
IPoint pt = null;
ISceneGraph pSG = axSceneControl1.SceneGraph;
ISceneViewer pSW = pSG.ActiveViewer;
object a;
object b;
pSG.Locate(pSW, e.x, e.y, esriScenePickMode.esriScenePickAll, true, out pt, out a, out b);
if (pt == null) return;
ptCol.Add(pt);
int i = ptCol.Count;
if (i < 1) return;
IRgbColor pRgbColor = new RgbColorClass();
pRgbColor.Blue = 255;
pRgbColor.Green = 0;
pRgbColor.Red = 0;
ISimpleLine3DSymbol pSimpleLine3DSymbol = new SimpleLine3DSymbolClass();
pSimpleLine3DSymbol.Style = esriSimple3DLineStyle.esriS3DLSTube;
ILineSymbol pLineSymbol = pSimpleLine3DSymbol as ILineSymbol;
pLineSymbol.Color = pRgbColor;
pLineSymbol.Width = 10;
//ILineElement pLineElement = new LineElementClass();
//pLineElement.Symbol = pLineSymbol;
//产生线段对象 line
ILine pLine = new LineClass();
IPoint fromPt = ptCol[i - 1];
IPoint toPt = ptCol[i - 2];
pLine.PutCoords(fromPt, toPt);
//将线段对象添加到多义线对象polyline
object Missing1 = Type.Missing;
object Missing2 = Type.Missing;
ISegment pSegment = pLine as ISegment;
m_polyline.AddSegment(pSegment, ref Missing1, ref Missing2);
//让Z值生效
IZAware Zaware = m_polyline as IZAware;
Zaware.ZAware = true;
IGeometry geometry = (IGeometry)m_polyline;
//更新到Graphics窗口
IGraphicsContainer3D pGCon3D = axSceneControl1.Scene.BasicGraphicsLayer as IGraphicsContainer3D;
IElement pElement = new LineElementClass();
pElement.Geometry = geometry;
ILineElement pLineElement = pElement as ILineElement;
pLineElement.Symbol = pLineSymbol;
pGCon3D.DeleteAllElements();
pGCon3D.AddElement(pElement);
axSceneControl1.Scene.SceneGraph.RefreshViewers();
}
是的,这段代码如果 axSceneControl1 加载的是.sxd文件确实可以画。且是画出的就是管子样式的线。那么么样改一下就能让加载.shp文件的axSceneControl1 也可以画呢。看代码:
public Form1()
{
InitializeComponent();
_axesGraphicsContainer3D = new GraphicsLayer3DClass();
ILayer layer = _axesGraphicsContainer3D as ILayer;
layer.Name = "XXX";
this.axSceneControl1.Scene.AddLayer(_axesGraphicsContainer3D as ILayer, true);
}
private void axSceneControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ISceneControlEvents_OnMouseDownEvent e)
{
IPoint pt = null;
ISceneGraph pSG = axSceneControl1.SceneGraph;
ISceneViewer pSW = pSG.ActiveViewer;
object a;
object b;
pSG.Locate(pSW, e.x, e.y, esriScenePickMode.esriScenePickAll, true, out pt, out a, out b);
if (pt == null) return;
ptCol.Add(pt);
int i = ptCol.Count;
if (i < 1) return;
IRgbColor pRgbColor = new RgbColorClass();
pRgbColor.Blue = 255;
pRgbColor.Green = 0;
pRgbColor.Red = 0;
ISimpleLine3DSymbol pSimpleLine3DSymbol = new SimpleLine3DSymbolClass();
pSimpleLine3DSymbol.Style = esriSimple3DLineStyle.esriS3DLSTube;
ILineSymbol pLineSymbol = pSimpleLine3DSymbol as ILineSymbol;
pLineSymbol.Color = pRgbColor;
pLineSymbol.Width = 10;
//ILineElement pLineElement = new LineElementClass();
//pLineElement.Symbol = pLineSymbol;
//产生线段对象 line
ILine pLine = new LineClass();
IPoint fromPt = ptCol[i - 1];
IPoint toPt = ptCol[i - 2];
pLine.PutCoords(fromPt, toPt);
//将线段对象添加到多义线对象polyline
object Missing1 = Type.Missing;
object Missing2 = Type.Missing;
ISegment pSegment = pLine as ISegment;
m_polyline.AddSegment(pSegment, ref Missing1, ref Missing2);
//让Z值生效
IZAware Zaware = m_polyline as IZAware;
Zaware.ZAware = true;
IGeometry geometry = (IGeometry)m_polyline;
//更新到Graphics窗口
IGraphicsContainer3D pGCon3D = this._axesGraphicsContainer3D; //这一行代码要改 IGraphicsContainer3D pGCon3D = axSceneControl1.Scene.BasicGraphicsLayer as IGraphicsContainer3D;
IElement pElement = new LineElementClass();
pElement.Geometry = geometry;
ILineElement pLineElement = pElement as ILineElement;
pLineElement.Symbol = pLineSymbol;
pGCon3D.DeleteAllElements();
pGCon3D.AddElement(pElement);
axSceneControl1.Scene.SceneGraph.RefreshViewers();
}
O了,这样,你用SceneControl加载一个中国地图的shp文件进来,再在上面点击鼠标几下试下,就能看到效果了。
分享到:
相关推荐
ArcEngine实现在SceneControl中画线
在arcengine的scenecontrol中使用Opengl
自定义设计炫丽的工具按钮(实现ArcSence中常用按钮功能),利用ArcEngine提供的SceneControl和相应的接口实现三维数据加载、显示、浏览、分析等功能,如坡度分析、通视分析剖面图绘制、自动生成等高线等。
ArcScene+AE+点击画线.pdf
如何在ArcEngine环境中的SceneControl中实现查询功能 75 删除FeatureClass中满足一定条件的Feature问题及解决办法! 77 创建孤立的要素类和数据集中的要素类 78 SUM Color of vertex symbols in edit 80 要素动态跟踪...
Scenecontrol中加入shape!!
dem高程点获取,c#代码示例及dem数据和access mdb点图层arcgis engine 10.2 + vs2010
iObject .NET 添加透明控件到scenecontrol上。该资源由超图技术资源中心提供。
ArcScene+AE+中获得当前的extent.pdf
结合九里山矿务局实测钻孔资料,采用网格索引算法构建煤层(不规则三角网)TIN,...再采用ArcEngine开发包中的SceneControl控件进行二次开发,实现巷道三维可视化。该研究对煤与瓦斯突出预测防治、巷道布局等有指导意义。
把线数据增加高程(增加Z值) SceneControl中实现画3DGraphics的方法 曲线距离的测量
scenecontrol汽车沿着指定录像行驶
1、根据高程点(excel文件)生成TIN。 2、TIN与DOM叠加构建三维场景。 3、根据TIN提取等高线。 4、模型导入
该压缩包中包含了AE开发中在scenecontrol中添加点线面的源代码和标注,三维坐标查询,三维功能开发的基本操作代码。
ArcGIS Engine 9 中文开发指南(带目录标签) 目 录 第一章 ArcGIS 引擎简介 1 ArcGIS 9 概览 2 ArcGIS 引擎概览 6 ArcGIS 引擎用户 10 ArcGIS 引擎功能 12 如何开始 16 使用本书 18 开发资源 19 第二章...
讲述了如何在SceneControl中添加TIN数据,稍微改变代码,在MapControl中也可以实现TIN数据的添加,以及图层的渲染
ArcGIS Engine中文开发指南 目 录 第一章 ArcGIS 引擎简介 1 ArcGIS 9 概览 2 ArcGIS 引擎概览 6 ArcGIS 引擎用户 10 ArcGIS 引擎功能 12 如何开始 16 使用本书 18 开发资源 19 第二章 ArcGIS 软件体系结构 21 ...
本范例讲解在SuperMap iClient for 3D中使用SceneControl类的pixelToGloe方法将屏幕二维点 Point 转换成地理坐标系下的三维点 Point3D,实现在CAD模型上画点并获取模型高程值。
GlobalControl和SceneControl 45 ReaderControl 46 TOCControl和ToolbarControl 47 用ToolbarControl建立应用程序 48 建立不带ToolbarControl应用程序 53 第四章 开发环境 55 微软组件对象模型 56 使用ArcObjects...
8、在三维控件SceneControl中添加Shapfile、jpg、tif等格式文件... 95 9、保存场景图片... 96 10、添加Raster数据... 96 11、生成TIN.. 97 12、设置图层基准高程... 107 13、点击查询... 115 14、转换TIN成...