阅读:2244回复:3
[原创]Mapcontrol加载显示栅格图层问题
<P> 小弟在Mapcontrol加载显示栅格图层时,要从RasterDataset中创建layer然后用Mapcontrol来加载.但我可视域分析生成的栅格结果是GeoDataset的,请问如何加载?QI好像行不通,下面是出错的代码,有哪位能帮忙解决一下,谢了.</P>
<P>Dim pOutputRaster1 As IGeoDataset<BR>Set pOutputRaster1 = pSurfaceOp.Visibility(pSurface, pObservers, esriGeoAnalysisVisibilityFrequency)</P> <P>Dim pRasterLayer As IRasterLayer<BR> Set pRasterLayer = New RasterLayer<BR> Dim prasterdateset3 As IRasterDataset<BR> <FONT color=#ff9900>Set pRasterdataset3 = pOutputRaster1 'QI</FONT></P> <P>pRasterLayer.CreateFromDataset pRasterdataset3</P> <P>MapControl1.AddLayer pRasterLayer</P> |
|
1楼#
发布于:2006-06-20 14:07
<P>下面是打开raster的函数</P>
<P>Public Sub AddRaster()<BR>Dim filesys As FileSystemObject<BR> Set filesys = New FileSystemObject<BR> If filesys.FileExists(imgpath) = True Then<BR> Dim wsfact As IWorkspaceFactory<BR> Set wsfact = New RasterWorkspaceFactory<BR> <BR> Dim ws As IRasterWorkspace<BR> Set ws = wsfact.OpenFromFile(pathname, 0)<BR> <BR> Dim rasterdata As IRasterDataset<BR> Set rasterdata = ws.OpenRasterDataset(imagename)<BR> <BR> Dim rasterlayer As IRasterLayer<BR> Set rasterlayer = New rasterlayer<BR> rasterlayer.CreateFromDataset rasterdata<BR> <BR> pmap.AddLayer rasterlayer<BR> pmxdoc.ActiveView.Extent = rasterlayer.AreaOfInterest<BR> pmxdoc.ActiveView.Refresh<BR> <BR> Else<BR> MsgBox "Image not found", vbExclamation, "Error"<BR> End If<BR>End Sub<BR></P> |
|
|
2楼#
发布于:2006-06-20 14:47
<P>给你一段代码,参考一下就明白了</P>
<P> If m_pRasLyr Is Nothing Then Exit Sub<BR> Dim dZFactor As Double<BR> If unueZFactor.Text = "" Then<BR> dZFactor = 1<BR> Else<BR> dZFactor = unueZFactor.Value<BR> End If<BR> If unueGridSize.Value <= 0 Then<BR> MessageBox.Show("栅格单位太小,完法完成操作,请重新输入!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error)<BR> unueGridSize.Focus()<BR> Exit Sub<BR> End If</P> <P> Try<BR> Me.Cursor = Cursors.WaitCursor<BR> Dim pSurfaceOp As ISurfaceOp2<BR> pSurfaceOp = New RasterSurfaceOp<BR> Dim pRAE As IRasterAnalysisEnvironment<BR> pRAE = pSurfaceOp</P> <P> pRAE.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, unueGridSize.Value)</P> <P> Dim pGeoDataset As IGeoDataset<BR> Dim pRasDescriptor As IRasterDescriptor<BR> Dim pRaster As IRaster<BR> pRaster = m_pRasLyr.Raster<BR> pRasDescriptor = New RasterDescriptor<BR> pRasDescriptor.Create(pRaster, Nothing, "")<BR> pGeoDataset = pRasDescriptor<BR> Dim pOutRaster As IGeoDataset<BR> If optDegree.Checked = True Then<BR> pOutRaster = pSurfaceOp.Slope(pGeoDataset, esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees, dZFactor)<BR> Else<BR> pOutRaster = pSurfaceOp.Slope(pGeoDataset, esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopePercentrise, dZFactor)<BR> End If<BR> If TypeOf pOutRaster Is IRaster Then<BR> Dim pOutRasLyr As IRasterLayer<BR> pOutRasLyr = New RasterLayer<BR> pOutRasLyr.CreateFromRaster(pOutRaster)<BR> pOutRasLyr.Name = "Slope of " ; cboSurface.Text<BR> modLayerOp.AddLyrToMapByLayerType(m_pMapControl, pOutRasLyr)<BR> End If<BR> pSurfaceOp = Nothing<BR> pRasDescriptor = Nothing<BR> pOutRaster = Nothing<BR> Catch ex As Exception<BR> MessageBox.Show(Err.Description, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error)<BR> Finally<BR> Me.Cursor = Cursors.Default<BR> Me.Close()<BR> End Try<BR> </P> |
|
|
3楼#
发布于:2006-06-20 15:53
<P>谢谢GIS和ZhouSky,程序可以通过了</P>
<P>但还有一个问题,我怎么才能控制它分级显示的颜色呢</P> <P>我是如下程序来操作的,但有一个是背景色,有一个是前景色,现在我想控制前景色显示两个颜色,而不是随机显示.谢谢了</P> <P> Dim pStretchRen As IRasterStretchColorRampRenderer<BR> Set pStretchRen = New RasterStretchColorRampRenderer<BR> Dim pRasRen As IRasterRenderer<BR> Set pRasRen = pStretchRen<BR> <BR> ' Set raster for the renderer and update<BR> Set pRasRen.Raster = pRasterLayer.Raster<BR> pRasRen.Update<BR>' Define two colors<BR> Dim pFromColor As IColor<BR> Dim pToColor As IColor<BR> Set pFromColor = New RgbColor<BR> pFromColor.RGB = RGB(253, 204, 200) '颜色1<BR> Set pToColor = New RgbColor<BR> pToColor.RGB = RGB(255, 255, 255) '背景色<BR> <BR> ' Create color ramp<BR> Dim pRamp As IAlgorithmicColorRamp<BR> Set pRamp = New AlgorithmicColorRamp<BR> pRamp.Size = 255</P> <P> <BR> pRamp.FromColor = pFromColor<BR> pRamp.ToColor = pToColor<BR> pRamp.CreateRamp True<BR> <BR>' Plug this colorramp into renderer and select a band<BR>pStretchRen.BandIndex = 0<BR>pStretchRen.ColorRamp = pRamp<BR> <BR> ' Update the renderer with new settings and plug into layer<BR>pRasRen.Update<BR>Set pRasterLayer.Renderer = pStretchRen</P> |
|