ArcEngine+C# TIN相关三维功能模块介绍(一)
1.TIN数据的加载
//下面代码是打开 E:\文件夹下名称为 tin 的 TIN数据。 //定位TIN数据
IWorkspaceFactory pWSFact = new TinWorkspaceFactoryClass(); IWorkspace pWS = pWSFact.OpenFromFile(@\ITinWorkspace pTinWS = pWS as ITinWorkspace; ITin pTin = pTinWS.OpenTin(\//将TIN变为TIN图层
ITinLayer pTinLayer = new TinLayerClass(); pTinLayer.Dataset = pTin; pTinLayer.Name = \
//用三维控件AxSceneControl加载(也可以用AxMapControl,但看到了只能是平面效果) this.axSceneControl1.Scene.AddLayer(pTinLayer, true); 2.TIN图层属性设置
这里介绍TIN模型Z轴缩放、沿Z轴上下偏移以及TIN的平面显示与三维显示之间的切换。其效果与在ArcScene中右击TIN图层,点击属性下设置Z unit conversion factor和Base Heights的效果一样。主要用到了访问三维数据属性的接口I3DProperties,这段代码也比较简单,相信大家稍微看一下就能明白,对应的功能可以复制后直接使用。
///
/// 获取TIN图层三维属性 ///
/// ///
public I3DProperties get3DProps(ITinLayer pTinLayer) {
I3DProperties p3DProps = null;
ILayerExtensions lyrExt = pTinLayer as ILayerExtensions; for (int i = 0; i < lyrExt.ExtensionCount; i++) {
if (lyrExt.get_Extension(i) is I3DProperties) {
p3DProps = lyrExt.get_Extension(i) as I3DProperties; } }
return p3DProps; }
///
/// TIN模型Z轴缩放,设置缩放因子,此函数要位于控件加载TIN图层事件后 ///
///
/// 1拉伸 public void SetTinLayerZFactor(ITinLayer pTinLayer, double ZFactor) {
I3DProperties p3DProps = get3DProps(pTinLayer); if (p3DProps != null) {
p3DProps.ZFactor = ZFactor;//设置高程缩放因子 p3DProps.Apply3DProperties(pTinLayer); } }
///
/// TIN模型整体上下偏移 ///
///
/// public void SetTinLayerOffset(ITinLayer pTinLayer, double offset) {
I3DProperties p3DProps = get3DProps(pTinLayer); if (p3DProps != null)
{
p3DProps.OffsetExpressionString = offset.ToString(); p3DProps.Apply3DProperties(pTinLayer); } }
///
///将TIN变为一个平面,并设置该平面的高程 ///
/// ///
public void SetTinLayerHeight(ITinLayer pTinLayer, double tinHeight) {
I3DProperties p3DProps = get3DProps(pTinLayer); if (p3DProps != null) {
p3DProps.BaseOption = esriBaseOption.esriBaseExpression; p3DProps.BaseExpressionString = tinHeight.ToString(); p3DProps.Apply3DProperties(pTinLayer); } }
///
/// 将平面TIN还原为三维立体形式 ///
/// public void SetTinAsBase(ITinLayer pTinLayer) {
I3DProperties p3DProps = get3DProps(pTinLayer); if (p3DProps != null) {
p3DProps.BaseOption = esriBaseOption.esriBaseSurface;
p3DProps.BaseSurface = pTinLayer as IFunctionalSurface; p3DProps.Apply3DProperties(pTinLayer); } }
3.TIN模型渲染
TIN模型有多种渲染方案,如:单色面渲染(Faces)、高程分级渲染(Elevation)、网格线渲染(Edges)、结点渲染(Nodes)等,这些渲染方案可以在ArcScene中通过TIN图层属性中的Symbology轻松地设置。下面介绍的是如何通过代码,以二次开发的方式进行设置。这里主要介绍单色面渲染和高程分级渲染,其他渲染方案感兴趣的朋友可以自己尝试一下。
单色面渲染(Faces)
高程分级渲染(Elevation) 3.1单色面渲染(Faces)
可以设置渲染的颜色,该颜色要使用IColor类型的值。 ///
/// 单色渲染TIN三维模型 ///
/// ///
public void TinFaceRenderer(ITinLayer TinLayer, IColor pColor) {
ITinLayer pTinLayer = TinLayer;
ITinRenderer pRenderNew = new TinFaceRenderer() as ITinRenderer;
ITinSingleSymbolRenderer pUVRenderer = pRenderNew as ITinSingleSymbolRenderer; ISimpleFillSymbol pSymbol = new SimpleFillSymbolClass(); pSymbol.Color = pColor;
pUVRenderer.Symbol = pSymbol as ISymbol;