happytt
路人甲
路人甲
  • 注册日期2006-02-12
  • 发帖数51
  • QQ
  • 铜币269枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2106回复:3

[原创]Mapcontrol加载显示栅格图层问题

楼主#
更多 发布于:2006-06-20 12:54
<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>
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
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>
举报 回复(0) 喜欢(0)     评分
zhousky
论坛版主
论坛版主
  • 注册日期2003-08-01
  • 发帖数281
  • QQ
  • 铜币1027枚
  • 威望3点
  • 贡献值0点
  • 银元0个
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>
不要看我噢
举报 回复(0) 喜欢(0)     评分
happytt
路人甲
路人甲
  • 注册日期2006-02-12
  • 发帖数51
  • QQ
  • 铜币269枚
  • 威望0点
  • 贡献值0点
  • 银元0个
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>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部