public void GetThicknessData(IRasterLayer rAlamoSurface, IFeatureLayer fThicknessProfile) { try { IFeature fProfile = fThicknessProfile.FeatureClass.GetFeature(11); IPointCollection pPointCollection = null; IPolyline pPolyLine = null; IGeometry pGeom = null; Double dCellSize = 30; IRasterSurface pRasterSurface = null; pRasterSurface.RasterBand = rasterBand; ISurface pSurface = pRasterSurface as ISurface; pPolyLine = fProfile.Shape as IPolyline; pPointCollection = pPolyLine as IPointCollection; pGeom = pPointCollection as IGeometry; IPoint tmpPt = null; IPoint tmpPt2 = null; IPoint stepPoint = null; int ArrayCtr, loopCount, ptCtr, sgCtr; ArrayCtr = 0; double[] XArray = new double[1000]; double[] YArray = new double[1000]; double[] ElevArray = new double[1000]; double pElev, dX, dY, segLength, runStep, riseStep, lastPointX, lastPointY, gridNoData; gridNoData = -99999; tmpPt = pPointCollection.get_Point(0); XArray[ArrayCtr] = tmpPt.X; YArray[ArrayCtr] = tmpPt.Y; pElev = pSurface.GetElevation(tmpPt); if (pElev != gridNoData) { ElevArray[ArrayCtr] = pElev; } for (ptCtr = 1; ptCtr <= pPointCollection.PointCount - 1; ptCtr++) { tmpPt.X = pPointCollection.get_Point(ptCtr - 1).X; tmpPt.Y = pPointCollection.get_Point(ptCtr - 1).Y; tmpPt2.X = pPointCollection.get_Point(ptCtr).X; tmpPt2.Y = pPointCollection.get_Point(ptCtr).Y; dX = (tmpPt2.X - tmpPt.X); dY = (tmpPt2.Y - tmpPt.Y); segLength = Math.Sqrt(Math.Pow(dX, 2) + Math.Pow(dY, 2)); runStep = dCellSize * (dX) / segLength; riseStep = dCellSize * (dY) / segLength; loopCount = (int)Math.Round((segLength * 10000) / (dCellSize * 10000)); //*10000 because the cell size is so small it causes a divide by zero error. lastPointX = tmpPt.X; lastPointY = tmpPt.Y; for (sgCtr = 1; sgCtr <= loopCount; sgCtr++) { ArrayCtr = ArrayCtr + 1; stepPoint.X = lastPointX + runStep; stepPoint.Y = lastPointY + riseStep; XArray[ArrayCtr] = stepPoint.X; YArray[ArrayCtr] = stepPoint.Y; pElev = pSurface.GetElevation(stepPoint); if (pElev != gridNoData) { ElevArray[ArrayCtr] = pElev; lastPointX = stepPoint.X; lastPointY = stepPoint.Y; } } if ((segLength * 10000) % (dCellSize * 10000) != 0) { ArrayCtr = ArrayCtr + 1; stepPoint.X = lastPointX + runStep; stepPoint.Y = lastPointY + riseStep; XArray[ArrayCtr] = stepPoint.X; YArray[ArrayCtr] = stepPoint.Y; pElev = pSurface.GetElevation(stepPoint); if (pElev != gridNoData) { ElevArray[ArrayCtr] = pElev; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
rasterSurface.RasterBand = rasterBand;
''' <summary> ''' Returns the surface from the layer with the specified name. ''' </summary> ''' <param name="layer">The layer whose surface will be returned</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function GetSurfaceFromLayer(ByVal layer As ILayer) As ISurface ' Get the actual surface from the layer. If TypeOf layer Is ITinLayer Then ' QI Dim tinLayer As ITinLayer = CType(layer, ITinLayer) ' Return surface from TIN layer. Return CType(tinLayer.Dataset, ISurface) ElseIf TypeOf layer Is IRasterLayer Then ' QI Dim rasterLayer As IRasterLayer = CType(layer, IRasterLayer) ' Get surface from 3d extension on layer. Dim layerExtensions As ILayerExtensions = CType(rasterLayer, ILayerExtensions) For i As Integer = 0 To layerExtensions.ExtensionCount - 1 Dim dddProperties As I3DProperties = CType(layerExtensions.Extension(i), I3DProperties) If Not dddProperties Is Nothing Then If dddProperties.BaseOption = esriBaseOption.esriBaseSurface Then If Not dddProperties.BaseSurface Is Nothing Then Return CType(dddProperties.BaseSurface, ISurface) End If End If Exit For End If Next i ' Get surface from raster band collection. Dim rasterBandCollection As IRasterBandCollection = CType(rasterLayer.Raster, IRasterBandCollection) Dim rasterBand As IRasterBand = rasterBandCollection.Item(0) Dim rasterSurface As IRasterSurface = New RasterSurface rasterSurface.RasterBand = rasterBand Return CType(rasterSurface, ISurface) Else Return Nothing End If End Function
pSurface = GetSurfaceFromLayer(pLayer.Name;
pRasterSurface.RasterBand = pRasterBands.Item(0);
pRasterSurface.RasterBand = pRasterBand
IFeature fProfile = fThicknessProfile.FeatureClass.GetFeature(11); IPointCollection pPointCollection = null; IPolyline pPolyLine = null; IGeometry pGeom = null; Double dCellSize = 30; IRasterBandCollection pRasterBands = null; pRasterBands = rAlamoSurface.Raster as IRasterBandCollection; IRasterBand pRasterBand = pRasterBands.Item(0); IRasterSurface pRasterSurface = null; //I get the error here....trying to cast an IRasterBand to an IRasterSurface pRasterSurface.RasterBand = pRasterBand as IRasterSurface; //I've found other VB.net references that use: //pRasterSurface.RasterBand = pRasterBand
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.