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


     

  • 相关阅读:
    画图工具Graphviz安装配置
    转:完善eclipse+pdt作php开发中的代码提示能力
    转:SVN 出现This client is too old to work with working copy...错误
    Codeforces Round #260 (Div. 2)C. Boredom(dp)
    three.js 源代码凝视(十四)Math/Sphere.js
    android项目中刷新activity界面
    中科燕园GIS外包---地铁GIS项目
    华为HCNA教程(笔记)
    HapiJS开发手冊
    《Java并发编程实战》第十四章 构建自己定义的同步工具 读书笔记
  • 原文地址:https://www.cnblogs.com/luspa/p/1264729.html
Copyright © 2011-2022 走看看