' Part 1: Define the temporary raster data. Dim pMxDoc As IMxDocument Dim pMap As IMap Dim pRasterLy As IRasterLayer Dim pRaster As IRaster Dim pRasBandC As IRasterBandCollection Dim pRasterDS As IRasterDataset Set pMxDoc = ThisDocument Set pMap = pMxDoc.FocusMap ' Get the raster from the raster layer. Set pRasterLy = pMap.Layer(0) Set pRaster = pRasterLy.Raster ' Set the raster dataset to be the first band of the raster Set pRasBandC = pRaster Set pRasterDS = pRasBandC.Item(0).RasterDataset Dim pRasterCursor As IRasterCursor Dim pRaster1 As IRaster2 Set pRaster1 = pRasterDS.CreateDefaultRaster Set pRasterCursor = pRaster1.CreateCursorEx(Nothing) 'use IRasterEdit interface Dim pRasterEdit As IRasterEdit Set pRasterEdit = pRaster1 'loop through each pixel block in the raster. Dim pPB As IPixelBlock3 Dim PixelBlockWidth As Long, PixelBlockHeight As Long ' Dim pTLC As IPnt Dim pBandCol As IRasterBandCollection Set pBandCol = pRasterDS ''''''''''''''' Dim v As Double Dim i As Integer Dim j As Integer Dim length As Integer length = 0 Dim VAL1(2890) As Double
'1990=2959 ‘这里要实现计算样带中的非零值个数 '2000=2961 '2005=2890 Do Set pPB = pRasterCursor.PixelBlock For i = 0 To pPB.Width - 1 For j = 0 To pPB.Height - 1 v = pPB.GetVal(0, i, j) If v <> 0 Then ’如果像元值不为零,则存入数据集中
VAL1(length) = v length = 1 + length End If Next j Next i
Loop While pRasterCursor.Next = True MsgBox length ' Dim l As Integer
l = length
Open "c:ndvi05.txt" For Output As #1 ‘记入文本 For i = 0 To l - 1 Step 1 Print #1, "," & VAL1(i);