首页 > 代码库 > 以AO方式给SceneControl控件设置BaseHeight

以AO方式给SceneControl控件设置BaseHeight

       用SceneContral控件给数据添加基本高度以显示三维效果,网上的例子很多,如下:

        private void addBaseHeight(IRasterLayer layer)
        {
            IRasterSurface pSurface = new RasterSurface();
            IRaster raster = (IRaster)layer.Raster;
            IRasterBandCollection rasterbands = raster as IRasterBandCollection;
            IRasterBand rasterband = rasterbands.Item(0);
            pSurface.RasterBand = rasterband;
         
            ILayerExtensions layerextensions = layer as ILayerExtensions;         
            I3DProperties properties = new Raster3DPropertiesClass();
            for (int i = 0; i < layerextensions.ExtensionCount; i++)
            {
                if (layerextensions.get_Extension(i) != null)
                {
                    properties = layerextensions.get_Extension(i) as I3DProperties;
                    break;
                }
            }
            properties.ZFactor = xx;
            properties.BaseOption = esriBaseOption.esriBaseSurface;
            properties.BaseSurface = pSurface as IFunctionalSurface;        
            properties.Apply3DProperties(layer);               

        }

       新手复制代码调试时很容易遇到的错误是layerextensions的ExtensionCount很有可能为0,是因为不能将三维属性赋给图层后再一起加到SceneControl里面,必须将没有带三维属性的layer预先添加至SceneControl控件,然后再赋予三维属性。这样一来ExtensionCount就不会为0了。

      另外扩展一点:给如FeatureLayer等非栅格数据设置基本高度,必须是要有其他Surface数据来作为支撑的,I3DProperties的BaseSurface属性不设则无效。

以AO方式给SceneControl控件设置BaseHeight