阅读:1075回复:0
大家有使用过Mosaic函数作影像镶嵌的吗?
<P>我使用IRasterGeometryProc接口的Mosaic镶嵌影像,对于只用一个波段的影像,代码的运行符合预期,但是对于多波段的影响,运行后发现新生成的影像的波段内容一样的,即全是第一个波段分量。其代码如下:</P>
<P>Private Function Mosaic(pSourRasterWorkspace As IRasterWorkspace, pSourLayer As Collection, pResuRasterWorkspace As IRasterWorkspace, strResuLayer) As IRaster<BR> <BR> Dim strSourFormat As String<BR> <BR> Dim pSourSpatialRef As ISpatialReference</P> <P> Dim dSourCellSize As Double<BR> <BR> Dim pvSourRasterBandCollection As Collection<BR> Set pvSourRasterBandCollection = New Collection<BR> <BR> Dim nvLayerCount As Long<BR> nvLayerCount = 1<BR> <BR> Dim pSourRasterBandCollection As IRasterBandCollection<BR> Dim pSourRasterBand As IRasterBand<BR> <BR> Dim nBandCount As Long<BR> Dim nMaxBandCount As Long<BR> <BR> Dim nLayerCount As Long<BR> nLayerCount = pSourLayer.Count<BR> <BR> Dim nLayerIndex As Long<BR> For nLayerIndex = 1 To nLayerCount<BR> Dim strLayer As String<BR> strLayer = pSourLayer.Item(nLayerIndex)<BR> <BR> Dim pSourRasterDataset As IRasterDataset<BR> Set pSourRasterDataset = pSourRasterWorkspace.OpenRasterDataset(strLayer)<BR> <BR> Debug.Assert Not pSourRasterDataset Is Nothing<BR> <BR> If nLayerIndex = 1 Then<BR> strSourFormat = pSourRasterDataset.Format<BR> <BR> Dim pSourRaster As IRaster<BR> Set pSourRaster = pSourRasterDataset.CreateDefaultRaster<BR> <BR> Dim pSourRasterProps As IRasterProps<BR> Set pSourRasterProps = pSourRaster<BR> <BR> Set pSourSpatialRef = pSourRasterProps.SpatialReference<BR> <BR> Dim pSourPnt As IPnt<BR> Set pSourPnt = pSourRasterProps.MeanCellSize<BR> <BR> Dim dSourCellSizeX As Double<BR> Dim dSourCellSizeY As Double<BR> <BR> dSourCellSizeX = pSourPnt.X<BR> dSourCellSizeY = pSourPnt.Y<BR> <BR> dSourCellSize = (dSourCellSizeX + dSourCellSizeY) / 2<BR> End If<BR> <BR> Dim strFormat As String<BR> strFormat = pSourRasterDataset.Format<BR> <BR> If strFormat = strSourFormat Then<BR> nBandCount = 0<BR> <BR> Set pSourRasterBandCollection = pSourRasterDataset<BR> nBandCount = pSourRasterBandCollection.Count<BR> <BR> If nBandCount > nMaxBandCount Then<BR> nMaxBandCount = nBandCount<BR> End If<BR> <BR> pvSourRasterBandCollection.Add pSourRasterBandCollection<BR> nvLayerCount = nvLayerCount + 1<BR> End If<BR> <BR> Next nLayerIndex<BR> <BR> Dim pResuRaster As IRaster<BR> Set pResuRaster = New Raster<BR> <BR> Dim pResuRasterBandCollection As IRasterBandCollection<BR> Set pResuRasterBandCollection = pResuRaster<BR> <BR> Dim nBandIndex As Long<BR> For nBandIndex = 0 To nMaxBandCount - 1<BR> <BR> Dim pTempRaster As IRaster<BR> Set pTempRaster = New Raster<BR> <BR> Dim pTempRasterBandCollection As IRasterBandCollection<BR> Set pTempRasterBandCollection = pTempRaster<BR> <BR> For nLayerIndex = 1 To nvLayerCount - 1<BR> Set pSourRasterBandCollection = pvSourRasterBandCollection.Item(nLayerIndex)<BR> <BR> If Not pSourRasterBandCollection Is Nothing Then<BR> Set pSourRasterBand = pSourRasterBandCollection.Item(nBandIndex)<BR> <BR> pTempRasterBandCollection.AppendBand pSourRasterBand<BR> End If<BR> Next nLayerIndex<BR> <BR> Dim pRasterGeometryProc As IRasterGeometryProc<BR> Set pRasterGeometryProc = New RasterGeometryProc<BR> <BR> Dim pMosaicedRaster As IRaster<BR> Set pMosaicedRaster = pRasterGeometryProc.Mosaic(CStr(nBandIndex + 1), pResuRasterWorkspace, strSourFormat, dSourCellSize, pSourSpatialRef, pTempRaster)</P> <P> Dim pMosaicedRasterBandCollection As IRasterBandCollection<BR> Set pMosaicedRasterBandCollection = pMosaicedRaster<BR> <BR> pResuRasterBandCollection.AppendBand pMosaicedRasterBandCollection.Item(0)</P> <P> Next nBandIndex<BR> <BR> pResuRasterBandCollection.SaveAs strResuLayer, pResuRasterWorkspace, strSourFormat<BR> <BR> Set Mosaic = pResuRasterBandCollection<BR> <BR>End Function</P> |
|