zoukankan      html  css  js  c++  java
  • 栅格重分类方法

    栅格重分类方法很多,在AE中有多种方式可以实现,使用地图代数(在RasterModel中实现),或者IReclassOp,或者Geoprocessor的方式都可以,甚至可以遍历栅格来实现,这是最原始的方式,不过也可能是最实用的。

    这里使用的是最原始的遍历栅格的方式。

     Public Function reclass(ByVal pRaster As IRaster, ByVal extent As ArrayList, ByVal value As ArrayList, ByVal NoData As Single) As IRaster


            '得倒栅格的IRasterProps和IRawPixels
            Dim pRasterBands As IRasterBandCollection
            pRasterBands = pRaster

            Dim pRasterBand As IRasterBand
            pRasterBand = pRasterBands.Item(0)

            Dim pRawRixels As IRawPixels
            pRawRixels = pRasterBands.Item(0)

            Dim pRasterPro As IRasterProps
            pRasterPro = pRasterBand

            '设置栅格数据起始点
            Dim pBlockSize As IPnt
            pBlockSize = New Pnt()

            pBlockSize.SetCoords(pRasterPro.Width, pRasterPro.Height)

            '在栅格上创建pPixBlock,用来存放栅格数据
            Dim pPixelBlock As IPixelBlock
            pPixelBlock = pRaster.CreatePixelBlock(pBlockSize)

            '左上点坐标
            Dim tlp As IPnt = New Pnt()
            tlp.SetCoords(0, 0)

            '读入栅格
            pRawRixels.Read(tlp, pPixelBlock)

            '将PixBlock的值组成数组
            Dim pSafeArray As System.Array
            pSafeArray = pPixelBlock.SafeArray(0)


            '遍历每一个栅格,进行分类设置
            For y As Long = 0 To pRasterPro.Height - 1
                For x As Long = 0 To pRasterPro.Width - 1

                    '判断每个栅格的所属类,确定其属于哪一类,然后进行赋值,即重分类
                    For i As Integer = 0 To extent.Count - 1

                        '如果值< 0,说明该处为空值(Nodata),赋给这个栅格相应的值
                        If CType(pSafeArray.GetValue(x, y), Single) < 0 Then
                            pSafeArray.SetValue(NoData, x, y)
                            Exit For
                        End If

                        '判断栅格属于哪一类,进行赋值
                        If CType(pSafeArray.GetValue(x, y), Single) <= CType(extent(i), Single) Then
                            pSafeArray.SetValue(value(i), x, y)
                            Exit For
                        End If
                    Next
                Next
            Next


            '将数组赋给PixBlock
            pPixelBlock.SafeArray(0) = CType(pSafeArray, System.Array)

            '编辑raster,将更新的值写入raster中
            Dim rasterEdit As IRasterEdit

            rasterEdit = pRaster
            rasterEdit.Write(tlp, pPixelBlock)
            rasterEdit.Refresh()

            Return pRaster

        End Function


     

  • 相关阅读:
    每日分享!JavaScript中的表单事件
    每日分享!~ 如何解决获取卷曲高度的问题,document.body.scrollTop为什么在pc端拿不到值
    Unhandled rejection Error: EACCES: permission denied, open '
    每日分享!canvas的使用~
    每日分享!JavaScript的鼠标事件(11个事件)
    每日分享!~ 使用js原生方式对拖拉元素(鼠标的事件)
    每日分享!~ JavaScript(拖拽事件)
    每日分享!~ JavaScript(js数组如何在指定的位置插入一个元素)
    每日分享!~ vue JavaScript中为什么可以读取到字符串的长度!(包装对象)
    let和var以及const有什么区别
  • 原文地址:https://www.cnblogs.com/luspa/p/1264729.html
Copyright © 2011-2022 走看看