阅读:2310回复:5
遇到奇怪问题,探讨探讨
我的想法是要把栅格文件类型中每个cell的值读出来,现在只能做出有某个值的cell有多少个(如值是5的cell有1022个)。但是遇到了奇怪的问题,我这段码对jpg,dem等都有效,不过遇到由ploygon转过来(用feature to raster)的栅格文件就会出现错误,此栅格文件有属性表。错误截图附上,请问是为什么??大家讨论下!
[此贴子已经被作者于2006-10-4 16:18:12编辑过]
|
|
|
1楼#
发布于:2006-10-07 10:19
<P>Sub countnumber()</P>
<P>Dim pMap As IMap<BR>Dim pMxDocument As IMxDocument<BR>Set pMxDocument = ThisDocument<BR>Set pMap = pMxDocument.FocusMap</P> <P>Dim pRasterlayer As IRasterLayer<BR>Set pRasterlayer = pMap.Layer(0)</P> <P>Dim pRaster As IRaster<BR>Set pRaster = pRasterlayer.Raster</P> <P>Dim pRasBC As IRasterBandCollection<BR>Set pRasBC = pRaster</P> <P>Dim pRasterBand As IRasterBand<BR>Set pRasterBand = pRasBC.Item(0)</P> <P>' This example shows the usage of the IRawPixels interface to<BR>' Read and write pixels to a raster band that is passed in.<BR>' QI for the IRawPixels interface<BR>Dim pRawPixels As IRawPixels<BR>Set pRawPixels = pRasterBand</P> <P>' QI for the IRasterProps interface to get height and width<BR>Dim pProps As IRasterProps<BR>Set pProps = pRaster</P> <P>Dim pPnt As IPnt<BR>Set pPnt = New DblPnt<BR>pPnt.SetCoords pProps.Width, pProps.Height</P> <P>' Use the RawPixels interface to create a new PixelBlock<BR>Dim pPixelBlock As IPixelBlock<BR>Set pPixelBlock = pRawPixels.CreatePixelBlock(pPnt)<BR>' Create a new point to specify where to begin reading, then read<BR>' Note:the origin is specified in pixel (or image) coordinates<BR>Dim pOrigin As IPnt<BR>Set pOrigin = New DblPnt<BR>pOrigin.SetCoords 0, 0<BR>pRawPixels.Read pOrigin, pPixelBlock</P> <P>' get the variant SafeArray from the pixelblock<BR>Dim vPixels As Variant<BR>vPixels = pPixelBlock.SafeArray(0)</P> <P>Dim i As Long, j As Long, sum As Long, value As Double</P> <P>value = InputBox("请输入元胞的值:", "输入框")</P> <P>For i = 0 To pProps.Width - 1<BR>For j = 0 To pProps.Height - 1<BR> If vPixels(i, j) = value Then sum = sum + 1<BR> Next<BR>Next</P> <P>MsgBox "此栅格图层中值为" ; value ; "的元胞有" ; sum ; "个"</P> <P>End Sub<BR></P> |
|
|
2楼#
发布于:2006-10-07 21:05
<img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em01.gif" />
|
|
3楼#
发布于:2006-10-08 22:02
<img src="images/post/smile/dvbbs/em08.gif" /><img src="images/post/smile/dvbbs/em03.gif" />
|
|
|
4楼#
发布于:2006-10-10 12:19
兄弟们有没遇到过这种问题啊??
|
|
|
5楼#
发布于:2006-10-14 16:53
我发现有些有属性表的栅格文件也能用,只不过它的pixle type是unsigned integer的,这个unsigned integer是什么意思,有什么办法可以把signed integer的改成unsigned integer的
|
|
|