Exemplo n.º 1
0
        private ISurface method_0(ILayer ilayer_1)
        {
            ISurface surface = null;

            if (ilayer_1 == null)
            {
                return(null);
            }
            if (ilayer_1 is ITinLayer)
            {
                ITinLayer layer = ilayer_1 as ITinLayer;
                return(layer.Dataset as ISurface);
            }
            if (ilayer_1 is IRasterLayer)
            {
                IRasterLayer   layer2   = ilayer_1 as IRasterLayer;
                IRasterBand    band     = (layer2.Raster as IRasterBandCollection).Item(0);
                IRasterSurface surface2 = new RasterSurfaceClass
                {
                    RasterBand = band
                };
                surface = surface2 as ISurface;
            }
            return(surface);
        }
Exemplo n.º 2
0
        private void comboBoxOpen_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (comboBoxOpen.Items.Count > 0)
                {
                    label.Text      = "";
                    DrawGeo.Enabled = false;
                    string LayerName = comboBoxOpen.SelectedItem.ToString();
                    ILayer pLayer    = GetLayerByName(ref LayerName);

                    if (pLayer is IRasterLayer)//读取Raster数据的ISurface
                    {
                        IRasterLayer      pRasterLayer = pLayer as IRasterLayer;
                        IGeoDataset       pDataset     = pRasterLayer as IGeoDataset;
                        ISpatialReference psr          = pDataset.SpatialReference;
                        //   ZQ   20110808   为处理地理坐标系与投影坐标系单位的转换
                        if (psr is IProjectedCoordinateSystem)
                        {
                            label.Text = "该数据为地理坐标,计算结果无效仅供参考!";
                        }
                        else if (psr is IGeographicCoordinateSystem)
                        {
                            //m_pMapControlDefault.MapUnits.ToString();
                        }
                        //
                        IRasterSurface pRasterSurface = new RasterSurfaceClass();
                        pRasterSurface.PutRaster(pRasterLayer.Raster, 0);
                        m_SurFace = pRasterSurface as ISurface;
                    }
                    else if (pLayer is ITinLayer)//读取TIN数据的ISurface
                    {
                        ITinLayer         pTinLayer = pLayer as ITinLayer;
                        IGeoDataset       pDataset  = pTinLayer as IGeoDataset;
                        ISpatialReference psr       = pDataset.SpatialReference;

                        if (!(psr is IProjectedCoordinateSystem))
                        {
                            label.Text = "该数据为地理坐标,计算结果无效仅供参考!";
                        }
                        m_SurFace = pTinLayer.Dataset as ISurface;
                    }
                    if (m_SurFace == null)
                    {
                        MessageBox.Show("请选择需要进行分析的DEM数据", "提示!");
                        return;
                    }

                    DrawGeo.Enabled = true;
                }
            }
            catch
            {
                return;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 获取分析图层及Surfer
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void comboBoxOpen_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (comboBoxOpen.Items.Count > 0)
     {
         string LayerName = comboBoxOpen.SelectedItem.ToString();
         m_Layer = GetLayerByName(ref LayerName);
         if (m_Layer is IRasterLayer)//读取Raster数据的ISurface
         {
             IRasterLayer   pRasterLayer   = m_Layer as IRasterLayer;
             IRasterSurface pRasterSurface = new RasterSurfaceClass();
             pRasterSurface.PutRaster(pRasterLayer.Raster, 0);
             m_Surface = pRasterSurface as ISurface;
         }
         else if (m_Layer is ITinLayer)//读取TIN数据的ISurface
         {
             ITinLayer pTinLayer = m_Layer as ITinLayer;
             m_Surface = pTinLayer.Dataset as ISurface;
         }
         if (m_Surface == null)
         {
             MessageBox.Show("请选择需要进行分析的DEM数据", "提示!");
             return;
         }
         pTool3DLineOfSight.m_Layer   = m_Layer;   //将当前选中的图层传给通视分析工具
         pTool3DLineOfSight.m_SurFace = m_Surface; //将当前获取的Surface传给通视分析工具
         //下面是根据获取的Surface来自动判断是否应用曲率和折射校正
         bool bCurvEnabled;
         bCurvEnabled = false;
         ISurface    pSurface = m_Surface;
         IGeoDataset pGeoDataset;
         if (pSurface is ITin)
         {
             pGeoDataset = pSurface as IGeoDataset;
         }
         else
         {
             IRasterSurface pRasterSurf = pSurface as IRasterSurface;
             pGeoDataset = pRasterSurf.RasterBand.RasterDataset as IGeoDataset;
         }
         ISpatialReference pSpatialReference = pGeoDataset.SpatialReference;
         ILinearUnit       pLinearUnit       = pSpatialReference.ZCoordinateUnit;
         if (pLinearUnit != null)
         {
             if (pSpatialReference is IProjectedCoordinateSystem)//当投影ProjectedCoordinateSystem时使用应用曲率和折射校正
             {
                 bCurvEnabled = true;
             }
         }
         checkBoxCurv.Checked = bCurvEnabled;
     }
 }
        private void SurfaceProcess(IGeoDataset beforeGeo, IGeoDataset afterGeo)
        {
            try
            {
                IRasterSurface rasterSurface = new RasterSurfaceClass();
                rasterSurface.PutRaster((IRaster)beforeGeo, 0);
                ISurface pSurface = rasterSurface as ISurface;

                surfaceArea = pSurface.GetSurfaceArea(h, esriPlaneReferenceType.esriPlaneReferenceAbove).ToString(".###") + "㎡";
                projectArea = pSurface.GetProjectedArea(h, esriPlaneReferenceType.esriPlaneReferenceAbove).ToString(".###") + "㎡";

                ISurfaceOp            SurfaceOp     = new RasterSurfaceOpClass();
                IGeoDataset           outGeoDataset = SurfaceOp.CutFill(beforeGeo, afterGeo, Type.Missing);
                IRasterBandCollection pRsBandCol    = outGeoDataset as IRasterBandCollection;

                double area       = 0.0; //涉及面积
                double volume     = 0.0; //挖方方量
                double volume1    = 0.0; //填方方量
                double sumVolume  = 0;   //挖方总量
                double sumVolume1 = 0;   //填方总量
                for (int i = 0; i < pRsBandCol.Count; i++)
                {
                    IRasterBand pBand   = pRsBandCol.Item(0);
                    ITable      pRTable = pBand.AttributeTable;
                    ICursor     pCursor = pRTable.Search(null, true);

                    IRow pRrow = pCursor.NextRow();
                    while (pRrow != null)
                    {
                        area  += Convert.ToDouble(pRrow.get_Value(pRrow.Fields.FindField("AREA")).ToString());
                        volume = Convert.ToDouble(pRrow.get_Value(pRrow.Fields.FindField("VOLUME")).ToString());
                        if (volume > 0)
                        {
                            sumVolume += volume;
                        }
                        else
                        {
                            sumVolume1 += volume;
                        }
                        pRrow = pCursor.NextRow();
                    }
                }
                dig  = Math.Round(sumVolume, 3).ToString() + "m³";
                fill = Math.Round(Math.Abs(sumVolume1), 3).ToString() + "m³";
            }
            catch (System.Exception ex)
            {
                WaitForm.Stop();
            }
        }
Exemplo n.º 5
0
        public IRasterSurface GetSurfFormLayer(IRasterLayer pRLayer)
        {
            I3DProperties p3DProp = Get3DPropsFromLayer((pRLayer));
            //获取图层的基准面
            IRasterSurface pRSurf = (IRasterSurface)p3DProp.BaseSurface;

            //如果空 则取栅格的第一个波段
            if (pRSurf == null)
            {
                //MessageBox.Show("null");
                pRSurf = new RasterSurfaceClass();
                IRasterBandCollection bands = (IRasterBandCollection)pRLayer.Raster;
                pRSurf.RasterBand = bands.Item(0);
            }
            return(pRSurf);
        }
        /// <summary>
        /// Initializes a new instance of the AnalysisSurface class
        /// </summary>
        /// <param name="rasterFromLayer">The raster from the layer</param>
        /// <param name="bandIndex">Index of the band</param>
        public AnalysisSurface(IRaster rasterFromLayer, int bandIndex)
        {
            IRasterBandCollection rasterBC = (IRasterBandCollection)rasterFromLayer;

            this.RasterBand    = rasterBC.Item(bandIndex);
            this.RasterDataset = this.RasterBand.RasterDataset;
            this.Raster        = this.RasterDataset.CreateDefaultRaster();

            IGeoDataset rasterGDS = (IGeoDataset)this.RasterDataset;

            this.SpatialReference = rasterGDS.SpatialReference;

            IRasterSurface rasterSurface = new RasterSurfaceClass();

            rasterSurface.PutRaster(this.Raster, bandIndex);
            this.Surface = (ISurface)rasterSurface;
        }
        /// <summary>
        /// Method to get a ISurface from a map with layer name
        /// </summary>
        /// <param name="map">IMap that contains surface layer</param>
        /// <param name="name">Name of the layer that you are looking for</param>
        /// <returns>ISurface</returns>
        public ISurface GetSurfaceFromMapByName(IMap map, string name)
        {
            var layers = map.get_Layers();
            var layer  = layers.Next();

            while (layer != null)
            {
                if (layer.Name != name)
                {
                    layer = layers.Next();
                    continue;
                }

                var tin = layer as ITinLayer;
                if (tin != null)
                {
                    return(tin.Dataset as ISurface);
                }

                var      rasterSurface = new RasterSurfaceClass() as IRasterSurface;
                ISurface surface       = null;

                var mosaicLayer = layer as IMosaicLayer;
                var rasterLayer = layer as IRasterLayer;

                if (mosaicLayer != null && mosaicLayer.PreviewLayer != null && mosaicLayer.PreviewLayer.Raster != null)
                {
                    rasterSurface.PutRaster(mosaicLayer.PreviewLayer.Raster, 0);
                }
                else if (rasterLayer != null && rasterLayer.Raster != null)
                {
                    rasterSurface.PutRaster(rasterLayer.Raster, 0);
                }

                surface = rasterSurface as ISurface;

                if (surface != null)
                {
                    return(surface);
                }
            }

            return(null);
        }
Exemplo n.º 8
0
        private ISurface method_1(IDataset idataset_0)
        {
            ISurface surface = null;

            if (idataset_0 is ITin)
            {
                return(idataset_0 as ISurface);
            }
            if (idataset_0 is IRasterBandCollection)
            {
                IRasterBand    band     = (idataset_0 as IRasterBandCollection).Item(0);
                IRasterSurface surface2 = new RasterSurfaceClass
                {
                    RasterBand = band
                };
                surface = surface2 as ISurface;
            }
            return(surface);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Method to get a ISurface from a map with layer name
        /// </summary>
        /// <param name="map">IMap that contains surface layer</param>
        /// <param name="name">Name of the layer that you are looking for</param>
        /// <returns>ISurface</returns>
        public ISurface GetSurfaceFromMapByName(IMap map, string name)
        {
            for (int x = 0; x < map.LayerCount; x++)
            {
                var layer = map.get_Layer(x);

                if (layer == null || layer.Name != name)
                {
                    continue;
                }

                var tin = layer as ITinLayer;
                if (tin != null)
                {
                    return(tin.Dataset as ISurface);
                }

                var      rasterSurface = new RasterSurfaceClass() as IRasterSurface;
                ISurface surface       = null;

                var mosaicLayer = layer as IMosaicLayer;
                var rasterLayer = layer as IRasterLayer;

                if (mosaicLayer != null && mosaicLayer.PreviewLayer != null && mosaicLayer.PreviewLayer.Raster != null)
                {
                    rasterSurface.PutRaster(mosaicLayer.PreviewLayer.Raster, 0);
                }
                else if (rasterLayer != null && rasterLayer.Raster != null)
                {
                    rasterSurface.PutRaster(rasterLayer.Raster, 0);
                }

                surface = rasterSurface as ISurface;

                if (surface != null)
                {
                    return(surface);
                }
            }

            return(null);
        }
Exemplo n.º 10
0
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            if(pFlag==1)//缓冲区空间查询
               {
               IActiveView pActView = axMapControl1.Map as IActiveView;

               IPoint pPoint = pActView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

               ITopologicalOperator pTopo = pPoint as ITopologicalOperator;

               IGeometry pGeo = pTopo.Buffer(500);

               ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
               rgbColor.Red = 255;

               ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit Cast
               ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
               simpleFillSymbol.Color = color;

               ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as ESRI.ArcGIS.Display.ISymbol;

               pActView.ScreenDisplay.SetSymbol(symbol);

               pActView.ScreenDisplay.DrawPolygon(pGeo);

               axMapControl1.Map.SelectByShape(pGeo, null, false);

               axMapControl1.FlashShape(pGeo, 1000, 2, symbol);

               axMapControl1.ActiveView.Refresh();
               }
               if (pFlag == 2)
               {
               pNetMap = axMapControl1.Map;

               pGC = pNetMap as IGraphicsContainer;

               IActiveView pActView = pNetMap as IActiveView;

               IPoint pPoint = pActView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

               object o = Type.Missing;
               object o1 = Type.Missing;

               pPointC.AddPoint(pPoint, ref o, ref o1);

               IElement Element;

               ITextElement Textelement = new TextElementClass();

               Element = Textelement as IElement;

               pClickedCount++;

               Textelement.Text = pClickedCount.ToString();

               Element.Geometry = pActView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

               pGC.AddElement(Element, 0);

               pActView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

               IFeatureClass pFeatureClass = pNaContext.NAClasses.get_ItemByName("Stops") as IFeatureClass;

               NASolve(pNaContext, pFeatureClass, pPointC, 5000);

               IGPMessages gpMessages = new GPMessagesClass();

               bool pBool = pNASolveClass.Solve(pNaContext, gpMessages, null);

               }

               if (pFlag == 3)//有向网络
               {
               IWorkspace pWs = GetMDBWorkspace(@".\data\Geometric.mdb");

               IFeatureWorkspace pFtWs = pWs as IFeatureWorkspace;

               IFeatureDataset pFtDataset = pFtWs.OpenFeatureDataset("work");

               double s = 0;

               IPolyline pPolyline = new PolylineClass();

               SolvePath(axMapControl1.Map, GetGeometricNetwork(pFtDataset, "TestGeometric"), "Weight", pPointC, 1000, ref pPolyline, ref s);

               IRgbColor pColor = new RgbColorClass();
               pColor.Red = 255;
               IElement pElement = new LineElementClass();
               ILineSymbol linesymbol = new SimpleLineSymbolClass();
               linesymbol.Color = pColor as IColor;
               linesymbol.Width = 100;

               pElement.Geometry = pPolyline;

               pGC.AddElement(pElement, 2);

               axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
               }
               if (pFlag == 4)
               {
               if(axMapControl1.Map.get_Layer(0)!=null)
               {
                   IRasterLayer pRasterLayer = axMapControl1.Map.get_Layer(0) as IRasterLayer;

                   IRasterSurface pRasterSurface = new RasterSurfaceClass();

                   pRasterSurface.PutRaster(pRasterLayer.Raster, 0);

                   ISurface pSurface = pRasterSurface as ISurface;

                  IPolyline pPolyline = axMapControl1.TrackLine() as  IPolyline;

                   IPoint pPoint =null ;

                    IPolyline pVPolyline =null;

                   IPolyline pInPolyline= null;

                   object pRef=0.13;

                   bool pBool =true;

                   double pZ1 = pSurface.GetElevation(pPolyline.FromPoint);

                   double pZ2= pSurface.GetElevation(pPolyline.ToPoint);

                   IPoint pPoint1 = new PointClass();

                   pPoint1.Z = pZ1;

                   pPoint1.X = pPolyline.FromPoint.X;

                   pPoint1.Y = pPolyline.FromPoint.Y;

                   IPoint pPoint2 = new PointClass();

                   pPoint2.Z = pZ2;

                   pPoint2.X = pPolyline.ToPoint.X;

                   pPoint2.Y = pPolyline.ToPoint.Y;

                   pSurface.GetLineOfSight(pPoint1, pPoint2, out pPoint, out pVPolyline,
                       out pInPolyline, out pBool, false, false, ref pRef);//大爷的,设置为true居然通不过bApplyCurvature和bApplyRefraction两项设置为true,surface必须定义成具有ZUnits的投影坐标

                   //This member should not be used in .NET. As a substitute, .NET developers must use IGeoDatabaseBridge2.GetLineOfSight.

                         //楼主,用IGeoDatabaseBridge2.GetLineOfSight.方法试试
                   if (pVPolyline != null)
                   {

                       IElement pLineElementV = new LineElementClass();

                       pLineElementV.Geometry = pVPolyline;

                       ILineSymbol pLinesymbolV = new SimpleLineSymbolClass();

                       pLinesymbolV.Width = 2;

                       IRgbColor pColorV = new RgbColorClass();

                       pColorV.Green =255;

                       pLinesymbolV.Color = pColorV;

                       ILineElement pLineV = pLineElementV as ILineElement;

                       pLineV.Symbol = pLinesymbolV;

                       axMapControl1.ActiveView.GraphicsContainer.AddElement(pLineElementV, 0);
                   }

                   if (pInPolyline != null)
                   {

                       IElement pLineElementIn = new LineElementClass();

                       pLineElementIn.Geometry = pInPolyline;

                       ILineSymbol pLinesymbolIn = new SimpleLineSymbolClass();

                       pLinesymbolIn.Width = 2;

                       IRgbColor pColorIn = new RgbColorClass();
                       pColorIn.Red = 255;

                       pLinesymbolIn.Color = pColorIn;
                       ILineElement pLineIn = pLineElementIn as ILineElement;

                       pLineIn.Symbol = pLinesymbolIn;

                       axMapControl1.ActiveView.GraphicsContainer.AddElement(pLineElementIn, 1);

                   }

                   axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                   axMapControl1.TrackCancel.Cancel();

               }
               }
        }
        /// <summary>
        /// Method to get a ISurface from a map with layer name
        /// </summary>
        /// <param name="map">IMap that contains surface layer</param>
        /// <param name="name">Name of the layer that you are looking for</param>
        /// <returns>ISurface</returns>
        public ISurface GetSurfaceFromMapByName(IMap map, string name)
        {
            for (int x = 0; x < map.LayerCount; x++)
            {
                var layer = map.get_Layer(x);

                if (layer == null || layer.Name != name)
                    continue;

                var tin = layer as ITinLayer;
                if (tin != null)
                {
                    return tin.Dataset as ISurface;
                }

                var rasterSurface = new RasterSurfaceClass() as IRasterSurface;
                ISurface surface = null;

                var mosaicLayer = layer as IMosaicLayer;
                var rasterLayer = layer as IRasterLayer;

                if (mosaicLayer != null && mosaicLayer.PreviewLayer != null && mosaicLayer.PreviewLayer.Raster != null)
                {
                    rasterSurface.PutRaster(mosaicLayer.PreviewLayer.Raster, 0);
                }
                else if (rasterLayer != null && rasterLayer.Raster != null)
                {
                    rasterSurface.PutRaster(rasterLayer.Raster, 0);
                }

                surface = rasterSurface as ISurface;

                if (surface != null)
                    return surface;
            }

            return null;
        }
Exemplo n.º 12
0
 //��դ�����ݲ��л�ñ���
 public static ISurface GetSurface(ILayer pLayer)
 {
     if (pLayer is ITinLayer)
     {
         ITinLayer pTinLayer = pLayer as ITinLayer;
         ITinAdvanced pTin = pTinLayer.Dataset as ITinAdvanced;
         return pTin as ISurface;
     }
     else
     {
         IRasterLayer pRasterLayer = pLayer as IRasterLayer;
         IRasterBandCollection pRasterBands = pRasterLayer.Raster as IRasterBandCollection;
         IRasterBand pRasterBand = pRasterBands.Item(0);
         IRasterSurface pRasterSurface = new RasterSurfaceClass();
         pRasterSurface.RasterBand = pRasterBand;
         IGeoDataset pGeoDataset = pRasterBand.RasterDataset as IGeoDataset;
         IRasterStatistics pRasterStats = pRasterBand.Statistics;
         return pRasterSurface as ISurface;
     }
 }
Exemplo n.º 13
0
        private void btnok_Click(object sender, EventArgs e)
        {
            try
            {
                ILayer       pLayer    = null;
                IRasterLayer pRlayer   = null;
                ITinLayer    pTinlayer = null;
                ISurface     pSurface  = null;

                for (int i = 0; i < pMapControl.LayerCount; i++)
                {
                    if (pMapControl.get_Layer(i).Name == cmblayer.SelectedItem.ToString())
                    {
                        pLayer = pMapControl.get_Layer(i);
                    }
                }
                if (pLayer is IRasterLayer)
                {
                    pRlayer = pLayer as IRasterLayer;
                    IRasterSurface rasterSurf = new RasterSurfaceClass();
                    rasterSurf.PutRaster(pRlayer.Raster, 0);
                    pSurface = rasterSurf as ISurface;
                }
                else if (pLayer is ITinLayer)
                {
                    pTinlayer = pLayer as ITinLayer;
                    ITin ptin = pTinlayer.Dataset;
                    pSurface = (ISurface)ptin;
                }
                IPolyline pPolyline = pFeature.ShapeCopy as IPolyline;
                IGeometry pProfLine;
                IPoint    m_StartPoint = pPolyline.FromPoint;
                IPoint    m_EndPoint   = pPolyline.ToPoint;
                object    size         = new object();

                pSurface.GetProfile(pPolyline, out pProfLine, ref size);

                IPolyline     pNewLine      = pProfLine as IPolyline;
                double        iii           = pPolyline.Length;
                List <double> ZValue        = new List <double>();
                List <double> DistanceValue = new List <double>();
                DistanceValue.Add(0);
                ZValue.Add(pNewLine.FromPoint.Z);

                for (int i = 1; i < (int)pNewLine.Length; i++)
                {
                    DistanceValue.Add(i);
                    ICurve pCurve;
                    pNewLine.GetSubcurve(0, DistanceValue[i], false, out pCurve);
                    ZValue.Add(pCurve.ToPoint.Z);
                }
                DistanceValue.Add(pNewLine.Length);
                ZValue.Add(pNewLine.ToPoint.Z);

                double    roffset = inoffset.Value / 2;  //右轮偏移
                double    loffset = -inoffset.Value / 2; //左轮偏移
                IPolyline pRLine  = ConstructOffset(pPolyline, roffset);
                IPolyline pLLine  = ConstructOffset(pPolyline, loffset);
                IGeometry pLProfLine;
                IGeometry pRProfLine;
                pSurface.GetProfile(pRLine, out pRProfLine, ref size);
                pSurface.GetProfile(pLLine, out pLProfLine, ref size);
                IPolyline     pRNewline      = pRProfLine as IPolyline;
                IPolyline     pLNewline      = pLProfLine as IPolyline;
                List <double> ZRValue        = new List <double>();
                List <double> ZLValue        = new List <double>();
                List <double> RDistanceValue = new List <double>();
                List <double> LDistanceValue = new List <double>();
                RDistanceValue.Add(0);
                LDistanceValue.Add(0);
                ZRValue.Add(pRNewline.FromPoint.Z);
                ZLValue.Add(pLNewline.FromPoint.Z);
                for (int j = 1; j < (int)pRNewline.Length; j++)
                {
                    RDistanceValue.Add(j);
                    ICurve pCurve;
                    pRNewline.GetSubcurve(0, RDistanceValue[j], false, out pCurve);
                    ZRValue.Add(pCurve.ToPoint.Z);
                }
                RDistanceValue.Add(pRNewline.Length);
                ZRValue.Add(pRNewline.ToPoint.Z);
                for (int k = 1; k < (int)pLNewline.Length; k++)
                {
                    LDistanceValue.Add(k);
                    ICurve pCurve;
                    pLNewline.GetSubcurve(0, LDistanceValue[k], false, out pCurve);
                    ZLValue.Add(pCurve.ToPoint.Z);
                }
                LDistanceValue.Add(pLNewline.Length);
                ZLValue.Add(pLNewline.ToPoint.Z);

                FrmprofileGraph frmgraph = new FrmprofileGraph(ZValue, DistanceValue, pNewLine, ZRValue, RDistanceValue, ZLValue, LDistanceValue);
                frmgraph.ShowDialog();
                frmgraph.ShowInTaskbar = false;
                frmgraph.StartPosition = FormStartPosition.CenterScreen;
                #region ///

                ////用ISurface的 InterpolateShape方法,得到这条直线做剖面后的Geometry,方法说明详见帮助

                //IGeometry OutShape;

                //object size = new object();
                //pSurface.InterpolateShape(pPolyline, out OutShape, ref size);

                ////将结果QI为 PointCollection,QI成功显示结果是直线上单一的几个离散点,InterpolateShape会自动将分析的结果直线上选取六个等分的离散点,以这六个点的值来作曲线图
                //IPointCollection pointCollection = OutShape as IPointCollection;
                //IMAware maware = pointCollection as IMAware;
                //maware.MAware = true;
                //IZAware zaware = pointCollection as IZAware;
                //zaware.ZAware = true;
                //IMSegmentation mseg = pointCollection as IMSegmentation;
                ////设置M的值为距离
                //mseg.SetMsAsDistance(false);

                //IPointCollection newPointColl = new PolylineClass();
                //int count = pointCollection.PointCount;
                //for (int i = 0; i < count; i++)
                //{
                //    IPoint point = pointCollection.get_Point(i);
                //    IPoint newPoint = new PointClass();
                //    newPoint.X = point.M;
                //    newPoint.Y = point.Z;
                //    object missing = Type.Missing;
                //    newPointColl.AddPoint(newPoint, ref missing, ref missing);
                //}

                //#region

                ////IWorkspaceFactory wsFactory = new ShapefileWorkspaceFactoryClass();

                ////IWorkspaceName workspaceName = wsFactory.Create("F:", "temp", null, 0);

                //IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
                //IWorkspaceName workspaceName = workspaceFactory.Create("", "MyWorkspace", null, 0);
                //IName name = workspaceName as IName;
                //IWorkspace workspace = name.Open() as IWorkspace;

                //IFields fields = new FieldsClass();
                //IFieldsEdit fieldsEdit = fields as IFieldsEdit;
                //IField field = new FieldClass();
                //IFieldEdit fieldEdit = field as IFieldEdit;
                //fieldEdit.Name_2 = "OID";
                //fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
                //fieldsEdit.AddField(field);

                //IGeometryDef geometryDef = new GeometryDefClass();
                //IGeometryDefEdit geometryDefEdit = geometryDef as IGeometryDefEdit;
                //geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
                //ISpatialReference spatialRef = new UnknownCoordinateSystemClass();
                //geometryDefEdit.SpatialReference_2 = (pRlayer as IGeoDataset).SpatialReference;


                //field = new FieldClass();
                //fieldEdit = field as IFieldEdit;
                //fieldEdit.Name_2 = "Shape";
                //fieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                //fieldEdit.GeometryDef_2 = geometryDef;
                //fieldsEdit.AddField(field);

                //IFieldChecker fieldChecker = new FieldCheckerClass();
                //IEnumFieldError enumFieldError = null;
                //IFields validatedFields = null;
                //fieldChecker.ValidateWorkspace = workspace;
                //fieldChecker.Validate(fields, out enumFieldError, out validatedFields);


                //IFeatureClass featureClass = (workspace as IFeatureWorkspace).CreateFeatureClass("test",
                //    validatedFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

                //IFeatureCursor featureCursor = featureClass.Insert(true);
                //IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
                //featureBuffer.Shape = pFeature as IGeometry;
                //featureCursor.InsertFeature(featureBuffer);
                //featureCursor.Flush();

                //#endregion

                //IFeatureLayer featureLayer = new FeatureLayerClass();
                //featureLayer.FeatureClass = featureClass;
                //featureLayer.Name = featureClass.AliasName;

                //pMapControl.AddLayer(featureLayer as ILayer);
                //pMapControl.Refresh();



                ////建立featureClass,为后面曲线图提供数据

                //IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
                //IWorkspaceName workspaceName = workspaceFactory.Create("", "MyWorkspace", null, 0);
                //IName name = (IName)workspaceName;
                //IWorkspace inmemWor = (IWorkspace)name.Open();

                //IFields fields = new FieldsClass();
                //IFieldsEdit fieldsEdit = fields as IFieldsEdit;
                //IField oidField = new FieldClass();
                //IFieldEdit oidFieldEdit = oidField as IFieldEdit;
                //oidFieldEdit.Name_2 = "OID";
                //oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
                //fieldsEdit.AddField(oidField);

                //IGeometryDef geometryDef = new GeometryDefClass();
                //IGeometryDefEdit geometryDefEdit = geometryDef as IGeometryDefEdit;
                //geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint;
                //geometryDefEdit.HasM_2 = true;
                //geometryDefEdit.HasZ_2 = true;
                //ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
                //ISpatialReference spatialReference = pMapControl.SpatialReference;//spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
                //ISpatialReferenceResolution spatialReferenceResolution = (ISpatialReferenceResolution)spatialReference; spatialReferenceResolution.ConstructFromHorizon();
                //ISpatialReferenceTolerance spatialReferenceTolerance = (ISpatialReferenceTolerance)spatialReference; spatialReferenceTolerance.SetDefaultXYTolerance();
                //geometryDefEdit.SpatialReference_2 = spatialReference;

                //IField geometryField = new FieldClass();
                //IFieldEdit geometryFieldEdit = (IFieldEdit)geometryField;
                //geometryFieldEdit.Name_2 = "Shape";
                //geometryFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                //geometryFieldEdit.GeometryDef_2 = geometryDef;
                //fieldsEdit.AddField(geometryField);

                //IField mField = new FieldClass();
                //IFieldEdit mFieldEdit = (IFieldEdit)mField;
                //mFieldEdit.Name_2 = "M";
                //mFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                //mFieldEdit.Length_2 = 8;
                //fieldsEdit.AddField(mField);

                //IField zField = new FieldClass();
                //IFieldEdit zFieldEdit = (IFieldEdit)zField;
                //zFieldEdit.Name_2 = "Z";
                //zFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                //zFieldEdit.Length_2 = 8;
                //fieldsEdit.AddField(zField);

                //IFieldChecker fieldChecker = new FieldCheckerClass();
                //IEnumFieldError enumFieldError = null;
                //IFields validatedFields = null;
                //fieldChecker.ValidateWorkspace = inmemWor;
                //fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

                //IFeatureClass featureClass = (inmemWor as IFeatureWorkspace).CreateFeatureClass("test", validatedFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

                //IFeatureCursor cursor = featureClass.Insert(true);
                //IFeatureBuffer buffer = featureClass.CreateFeatureBuffer();
                //int count = pointCollection.PointCount;
                //for (int i = 0; i < count; ++i)
                //{
                //    IPoint p = pointCollection.get_Point(i);
                //    buffer.Shape = p as IGeometry;
                //    buffer.set_Value(buffer.Fields.FindField("M"), p.M);
                //    buffer.set_Value(buffer.Fields.FindField("Z"), p.Z);
                //    cursor.InsertFeature(buffer);
                //}

                //cursor.Flush();

                ////开始做曲线图

                #endregion
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("该图像不能做剖面分析", "提示", MessageBoxButtons.OK);
            }
        }
        /// <summary>
        /// Method to get all the names of the raster/tin layers that support ISurface
        /// we use this method to populate a combobox for input selection of surface layer
        /// </summary>
        /// <param name="map">IMap</param>
        /// <returns></returns>
        public List<string> GetSurfaceNamesFromMap(IMap map, bool IncludeTinLayers = false)
        {
            var list = new List<string>();

            for (int x = 0; x < map.LayerCount; x++)
            {
                try
                {
                    var layer = map.get_Layer(x);

                    if (layer == null)
                        continue;

                    var tin = layer as ITinLayer;

                    if (tin != null)
                    {
                        if (IncludeTinLayers)
                            list.Add(layer.Name);

                        continue;
                    }

                    var rasterSurface = new RasterSurfaceClass() as IRasterSurface;
                    ISurface surface = null;

                    var ml = layer as IMosaicLayer;

                    if (ml != null)
                    {
                        if (ml.PreviewLayer != null && ml.PreviewLayer.Raster != null)
                        {
                            rasterSurface.PutRaster(ml.PreviewLayer.Raster, 0);

                            surface = rasterSurface as ISurface;
                            if (surface != null)
                                list.Add(layer.Name);
                        }
                        continue;
                    }

                    var rasterLayer = layer as IRasterLayer;
                    if (rasterLayer != null && rasterLayer.Raster != null)
                    {
                        rasterSurface.PutRaster(rasterLayer.Raster, 0);

                        surface = rasterSurface as ISurface;
                        if (surface != null)
                            list.Add(layer.Name);
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }

            return list;
        }
Exemplo n.º 15
0
 public IRasterSurface GetSurfFormLayer(IRasterLayer pRLayer)
 {
     I3DProperties p3DProp = Get3DPropsFromLayer((pRLayer));
     //获取图层的基准面
     IRasterSurface pRSurf = (IRasterSurface)p3DProp.BaseSurface;
     //如果空 则取栅格的第一个波段
     if (pRSurf == null)
     {
         //MessageBox.Show("null");
         pRSurf = new RasterSurfaceClass();
         IRasterBandCollection bands = (IRasterBandCollection)pRLayer.Raster;
         pRSurf.RasterBand = bands.Item(0);
     }
     return pRSurf;
 }
        /// <summary>
        /// Method to get all the names of the raster/tin layers that support ISurface
        /// we use this method to populate a combobox for input selection of surface layer
        /// </summary>
        /// <param name="map">IMap</param>
        /// <returns></returns>
        public List <string> GetSurfaceNamesFromMap(IMap map, bool IncludeTinLayers = false)
        {
            var list = new List <string>();

            var layers = map.get_Layers();
            var layer  = layers.Next();

            while (layer != null)
            {
                try
                {
                    var tin = layer as ITinLayer;

                    if (tin != null)
                    {
                        if (IncludeTinLayers)
                        {
                            list.Add(layer.Name);
                        }
                        layer = layers.Next();
                        continue;
                    }

                    var      rasterSurface = new RasterSurfaceClass() as IRasterSurface;
                    ISurface surface       = null;

                    var ml = layer as IMosaicLayer;

                    if (ml != null)
                    {
                        if (ml.PreviewLayer != null && ml.PreviewLayer.Raster != null)
                        {
                            rasterSurface.PutRaster(ml.PreviewLayer.Raster, 0);

                            surface = rasterSurface as ISurface;
                            if (surface != null)
                            {
                                list.Add(layer.Name);
                            }
                        }
                        layer = layers.Next();
                        continue;
                    }

                    var rasterLayer = layer as IRasterLayer;
                    if (rasterLayer != null && rasterLayer.Raster != null)
                    {
                        rasterSurface.PutRaster(rasterLayer.Raster, 0);

                        surface = rasterSurface as ISurface;
                        if (surface != null)
                        {
                            list.Add(layer.Name);
                        }
                        layer = layers.Next();
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

                layer = layers.Next();
            }

            return(list);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 获取分析图层及Surfer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBoxOpen_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (comboBoxOpen.Items.Count > 0)
                {
                    label.Text = "";
                    Cls3DMarkDraw.DeleteAllElementsWithName(m_pCurrentSceneControl.Scene, sRefPlaneName);
                    Cls3DMarkDraw.DeleteAllElementsWithName(m_pCurrentSceneControl.Scene, ContourName);
                    m_pCurrentSceneControl.SceneGraph.RefreshViewers();
                    m_ScenePoly         = null;
                    m_StaPolygon        = null;
                    m_SurFace           = null;
                    txtArea2DSel.Text   = "";
                    txtAreaAbove.Text   = "";
                    txtAreaBelow.Text   = "";
                    txtPara.Text        = "";
                    txtPlaneHeight.Text = "";
                    txtVolumeAbove.Text = "";
                    txtVolumeBelow.Text = "";

                    DrawGeo.Enabled        = false;
                    sldPlaneHeight.Enabled = false;
                    btncount.Enabled       = false;
                    string LayerName = comboBoxOpen.SelectedItem.ToString();
                    ILayer pLayer    = GetLayerByName(ref LayerName);

                    if (pLayer is IRasterLayer)//读取Raster数据的ISurface
                    {
                        IRasterLayer      pRasterLayer = pLayer as IRasterLayer;
                        IGeoDataset       pDataset     = pRasterLayer as IGeoDataset;
                        ISpatialReference psr          = pDataset.SpatialReference;

                        if (!(psr is IProjectedCoordinateSystem))
                        {
                            label.Text = "该数据为地理坐标,计算结果无效仅供参考!";
                        }

                        IRasterSurface pRasterSurface = new RasterSurfaceClass();
                        pRasterSurface.PutRaster(pRasterLayer.Raster, 0);
                        m_SurFace       = pRasterSurface as ISurface;
                        DrawGeo.Enabled = false;
                        m_IsTin         = false;
                    }
                    else if (pLayer is ITinLayer)//读取TIN数据的ISurface
                    {
                        ITinLayer         pTinLayer = pLayer as ITinLayer;
                        IGeoDataset       pDataset  = pTinLayer as IGeoDataset;
                        ISpatialReference psr       = pDataset.SpatialReference;

                        if (!(psr is IProjectedCoordinateSystem))
                        {
                            label.Text = "该数据为地理坐标,计算结果无效仅供参考!";
                        }

                        m_SurFace       = pTinLayer.Dataset as ISurface;
                        m_IsTin         = true;
                        DrawGeo.Enabled = true;
                    }
                    if (m_SurFace == null)
                    {
                        MessageBox.Show("请选择需要进行分析的DEM数据", "提示!");
                        return;
                    }
                    if (m_StaPolygon == null)
                    {
                        if (m_SurFace is ITin)
                        {
                            ITin pTin = m_SurFace as ITin;
                            sldPlaneHeight.Maximum = Convert.ToInt32(pTin.Extent.ZMax);
                            sldPlaneHeight.Minimum = Convert.ToInt32(pTin.Extent.ZMin);
                        }
                        else
                        {
                            IRasterSurface    pRasterSurface   = m_SurFace as IRasterSurface;
                            IRasterStatistics pRasterStatistic = pRasterSurface.RasterBand.Statistics;
                            sldPlaneHeight.Maximum = Convert.ToInt32(pRasterStatistic.Maximum);
                            sldPlaneHeight.Minimum = Convert.ToInt32(pRasterStatistic.Minimum);
                        }
                        double Vale = sldPlaneHeight.Maximum + sldPlaneHeight.Minimum;
                        Vale = Vale / 2;
                        txtPlaneHeight.Text = Vale.ToString();
                        Vale = Convert.ToDouble(txtPlaneHeight.Text);
                        sldPlaneHeight.Value = Convert.ToInt32(Vale);
                    }
                    else
                    {
                        double zrange;
                        zrange = m_StaPolygon.Envelope.ZMax - m_StaPolygon.Envelope.ZMin;
                        sldPlaneHeight.Maximum = Convert.ToInt32(m_StaPolygon.Envelope.ZMax + zrange);
                        sldPlaneHeight.Minimum = Convert.ToInt32(m_StaPolygon.Envelope.ZMin);
                        sldPlaneHeight.Value   = Convert.ToInt32(Math.Round(m_StaPolygon.Envelope.ZMin + (zrange * 0.5)));
                        txtPlaneHeight.Text    = sldPlaneHeight.Value.ToString();
                    }
                    sldPlaneHeight.Enabled = true;
                    btncount.Enabled       = true;
                }
            }
            catch
            {
                return;
            }
        }
Exemplo n.º 18
0
        private ISurface GetSurfaceFromLayer(ILayer player)
        {
            try
            {
                IRasterLayer     pRLayer;
                I3DProperties    p3DProp = null;
                ILayerExtensions pLE;
                IRasterSurface   pSurface = null;;
                ITinLayer        pTLayer;



                if (player is IRasterLayer)
                {
                    pRLayer = player as IRasterLayer;
                    pLE     = player as ILayerExtensions;

                    for (int i = 0; i <= pLE.ExtensionCount - 1; i++)
                    {
                        if (pLE.get_Extension(i) is I3DProperties)
                        {
                            p3DProp = pLE.get_Extension(i) as I3DProperties;
                            break;
                        }
                    }



                    if (p3DProp == null)
                    {
                        IRasterBandCollection pBands;
                        if (pRLayer.Raster != null)
                        {
                            pSurface            = new RasterSurfaceClass();
                            pBands              = pRLayer.Raster as IRasterBandCollection;
                            pSurface.RasterBand = pBands.Item(0);
                        }
                        return(pSurface as ISurface);
                    }
                    else
                    {
                        pSurface = p3DProp.BaseSurface as IRasterSurface;
                    }
                    return(pSurface as ISurface);
                }

                else
                {
                    if (player is ITinLayer)
                    {
                        pTLayer = player as ITinLayer;
                        return(pTLayer.Dataset as ISurface);
                    }
                }
                return(null);
            }

            catch (Exception ex)
            {
                string g = ex.Message;
                return(null);
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            try
            {
                if (m_application == null)
                {
                    return;
                }
                IDocument   document   = m_application.Document;
                ISxDocument sxDocument = (ISxDocument)(document);
                if (sxDocument != null)
                {
                    m_scene = sxDocument.Scene;
                }
                if (m_scene == null)
                {
                    return;
                }
                activeView = m_scene as IActiveView;

                //有图层选图层
                if (m_scene.LayerCount == 0)
                {
                    return;
                }

                //选择基准面
                if (Common.SelectLayer(m_scene.Layers, out SelectedLyrIndex, true, "选择自定义表面") == false)
                {
                    return;
                }

                //QI
                IRasterLayer baseRasterLayer = m_scene.Layer[SelectedLyrIndex[0]] as IRasterLayer;  //不管选多少个只选第一个
                if (baseRasterLayer == null)
                {
                    throw new ArgumentNullException("自定义表面RasterLayer转换失败,为空。");
                }
                IRaster raster = baseRasterLayer.Raster;
                if (raster == null)
                {
                    throw new ArgumentNullException("自定义表面Raster转换失败,为空。");
                }
                IRasterSurface rasterSurface = new RasterSurfaceClass();
                rasterSurface.PutRaster(raster, 0);
                ISurface surface = rasterSurface as ISurface;

                //选择图层
                if (Common.SelectLayer(m_scene.Layers, out SelectedLyrIndex, false, "选择要进行偏移的图层") == false)
                {
                    return;
                }

                //选择倍数
                NumSelect MultiNS = new NumSelect("输入夸大倍数", true);
                if (MultiNS.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                double Multiplier = MultiNS.Result;

                //选择偏移量
                NumSelect NS = new NumSelect();
                if (NS.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                double Offset       = NS.Result;
                bool   DisableCache = NS.DisableCache;

                //Create a CancelTracker.
                ITrackCancel pTrackCancel = new CancelTrackerClass();

                //Create the ProgressDialog. This automatically displays the dialog
                IProgressDialogFactory pProgDlgFactory = new ProgressDialogFactoryClass();
                IProgressDialog2       pProDlg         = pProgDlgFactory.Create(pTrackCancel, m_application.hWnd) as IProgressDialog2;
                pProDlg.CancelEnabled = true;
                pProDlg.Title         = "正在进行自定义表面设置及偏移调整";
                pProDlg.Description   = "设置中,请稍候...";

                pProDlg.Animation = esriProgressAnimationTypes.esriProgressSpiral;

                IStepProgressor pStepPro = pProDlg as IStepProgressor;
                pStepPro.MinRange  = 0;
                pStepPro.MaxRange  = SelectedLyrIndex.Count;
                pStepPro.StepValue = 1;
                pStepPro.Message   = "初始化中...";

                bool bCont = true;

                //对每一个选中的图层进行操作
                for (int i = 0; i < SelectedLyrIndex.Count; i++)
                {
                    //m_application.StatusBar.set_Message(0, i.ToString());
                    pStepPro.Message = "已完成(" + i.ToString() + "/" + SelectedLyrIndex.Count.ToString() + ")";
                    bCont            = pTrackCancel.Continue();
                    if (!bCont)
                    {
                        break;
                    }

                    //选中一个栅格图层
                    IRasterLayer rasterLayer = m_scene.Layer[SelectedLyrIndex[i]] as IRasterLayer;
                    if (rasterLayer == null)
                    {
                        pStepPro.Message = "选中的图层非栅格图层...";
                        continue;
                    }

                    I3DProperties    p3DProperties   = null;
                    ILayerExtensions layerExtensions = rasterLayer as ILayerExtensions;

                    //遍历LayerExtensions找到I3DProperties
                    for (int j = 0; j < layerExtensions.ExtensionCount; j++)
                    {
                        if (layerExtensions.get_Extension(j) is I3DProperties)
                        {
                            p3DProperties = layerExtensions.get_Extension(j) as I3DProperties;
                        }
                    }

                    //设置I3DProperties
                    p3DProperties.ZFactor                = Multiplier;                     //系数
                    p3DProperties.BaseOption             = esriBaseOption.esriBaseSurface; //基准面浮动
                    p3DProperties.BaseSurface            = surface;                        //基准面
                    p3DProperties.OffsetExpressionString = Offset.ToString();              //偏移常量
                    if (DisableCache)
                    {
                        p3DProperties.RenderMode       = esriRenderMode.esriRenderImmediate;         //直接从文件渲染
                        p3DProperties.RenderVisibility = esriRenderVisibility.esriRenderWhenStopped; //停止导航时渲染
                    }
                    p3DProperties.Apply3DProperties(rasterLayer);
                }
                pProDlg.HideDialog();

                //==========================================
                //刷新,不起作用
                if (activeView == null)
                {
                    throw new Exception("活动视图为空! ");
                }
                if (m_sceneHookHelper.ActiveViewer == null)
                {
                    throw new Exception("无活动视图!");
                }
                activeView.Refresh();
                m_sceneHookHelper.ActiveViewer.Redraw(true);
                //==========================================
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString());
            }
        }
Exemplo n.º 20
0
 double GetElevation(IRaster pRaster, IPoint point)
 {
     IRasterSurface pRasterSurface = new RasterSurfaceClass();
          pRasterSurface.PutRaster(pRaster, 0);
          ISurface pSurface = pRasterSurface as ISurface;
          return pSurface.GetElevation(point);
 }
Exemplo n.º 21
0
        private ISurface GetSurfaceFromLayer(ILayer player)
        {
            try
            {
                IRasterLayer pRLayer;
                I3DProperties p3DProp = null;
                ILayerExtensions pLE;
                IRasterSurface pSurface = null; ;
                ITinLayer pTLayer;

                if (player is IRasterLayer)
                {
                    pRLayer = player as IRasterLayer;
                    pLE = player as ILayerExtensions;

                    for (int i = 0; i <= pLE.ExtensionCount - 1; i++)
                    {
                        if (pLE.get_Extension(i) is I3DProperties)
                        {
                            p3DProp = pLE.get_Extension(i) as I3DProperties;
                            break;
                        }
                    }

                    if (p3DProp == null)
                    {
                        IRasterBandCollection pBands;
                        if (pRLayer.Raster != null)
                        {
                            pSurface = new RasterSurfaceClass();
                            pBands = pRLayer.Raster as IRasterBandCollection;
                            pSurface.RasterBand = pBands.Item(0);
                        }
                        return pSurface as ISurface;
                    }
                    else
                    {
                        pSurface = p3DProp.BaseSurface as IRasterSurface;
                    }
                    return pSurface as ISurface;

                }

                else
                {
                    if (player is ITinLayer)
                    {
                        pTLayer = player as ITinLayer;
                        return pTLayer.Dataset as ISurface;

                    }

                }
                return null;

            }

            catch (Exception ex)
            {
                string g = ex.Message;
                return null;
            }
        }