首页新闻找找看学习计划

请问如果用VBA编程获取影像的灰度值,怎么过滤掉那些栅格是nodata的呢?

0
[待解决问题]

请问如果用VBA编程获取影像的灰度值,怎么过滤掉那些栅格是nodata的呢?

或者怎么知道是nodata的?IPixelBlock的hasnodata方法怎么用呢?
下面是我的代码:

 1 ' Part 1: Define the temporary raster data.
 2     Dim pMxDoc As IMxDocument
 3     Dim pMap As IMap
 4     Dim pRasterLy As IRasterLayer
 5     Dim pRaster As IRaster
 6     Dim pRasBandC As IRasterBandCollection
 7     Dim pRasterDS As IRasterDataset
 8    
 9     Set pMxDoc = ThisDocument
10     Set pMap = pMxDoc.FocusMap
11     ' Get the raster from the raster layer.
12     Set pRasterLy = pMap.Layer(0)
13     Set pRaster = pRasterLy.Raster
14    
15     ' Set the raster dataset to be the first band of the raster 设置栅格数据集是第一波段光栅
16     Set pRasBandC = pRaster
17     Set pRasterDS = pRasBandC.Item(0).RasterDataset
18    
19     Dim pRasterCursor As IRasterCursor
20     Dim pRaster1 As IRaster2
21    
22     Set pRaster1 = pRasterDS.CreateDefaultRaster
23     
24     Dim pRasProps As IRasterProps
25     Set pRasProps = pRasterLy.Raster
26 
27     Dim pPnt As IPnt
28     Set pPnt = New Pnt
29     pPnt.SetCoords pRasProps.Width, pRasProps.Height
30         
31     Set pRasterCursor = pRaster1.CreateCursorEx(pPnt)
32   
33     'use IRasterEdit interface
34     'Dim pRasterEdit As IRasterEdit
35     'Set pRasterEdit = pRaster1
36    
37     'loop through each pixel block in the raster.
38     Dim pPB As IPixelBlock3
39     'Dim PixelBlockWidth As Long, PixelBlockHeight As Long
40     'Dim pBandCol As IRasterBandCollection
41     'Set pBandCol = pRasterDS
42    
43    
44    
45     
46     Dim v As Double
47     Dim i As Long
48     Dim j As Long
49     Dim length As Long
50     length = 0
51    
52     Dim VAL1(10000000) As Double
53     
54     
55     Do
56         Set pPB = pRasterCursor.PixelBlock
57             For i = 0 To pPB.Width - 1
58                 For j = 0 To pPB.Height - 1
59                     'If pPB.HasNoData(0) Then
60                         v = pPB.GetVal(0, i, j)
61                         VAL1(length) = v
62                         length = length + 1
63                     'End If
64                 Next j
65             Next i
66     Loop While pRasterCursor.Next = True
67    
68     MsgBox length
yycGIS的主页 yycGIS | 菜鸟二级 | 园豆:202
提问于:2013-04-11 13:05
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册