TIN TO RASTER

1 

 

 

Supported pixel types limited to float and long because output currently limited to native ESRI Grid
Public Function TinToRaster(pTin As ITinAdvanced, eRastConvType As esriRasterizationType, _
    sDir As String, sName As String, ePixelType As rstPixelType, cellsize As Double, pExtent As IEnvelope, _
    bPerm As Boolean) As IRasterDataset

 

    ' The origin used by CreateRasterDataset is the lower left cell corner.
    ' The extent passed is that of the TIN's.
    ' Define the raster origin and number of rows and columns so that the raster
    ' is of sufficient extent to capture all the TIN's data area.
    Dim pOrigin As IPoint
    Set pOrigin = pExtent.LowerLeft
    pOrigin.X = pOrigin.X - (cellsize * 0.5)
    pOrigin.Y = pOrigin.Y - (cellsize * 0.5)
    Dim nCol As Long, nRow As Long
    nCol = Round(pExtent.Width / cellsize) + 1
    nRow = Round(pExtent.Height / cellsize) + 1
    Dim pGDS As IGeoDataset
    Set pGDS = pTin
    Dim pSR As ISpatialReference2
    Set pSR = pGDS.SpatialReference
    Dim pRDS As IRasterDataset
    Set pRDS = CreateRasterSurf(sDir, sName, "GRID", pOrigin, nCol, nRow, cellsize, cellsize, ePixelType, pSR, bPerm)
    Dim pRawPixels As IRawPixels
    Set pRawPixels = GetRawPixels(pRDS, 0)
    ' TODO - this implementation is allocating one block for the entire extent. It may be resource
    ' intensive. A more resource friendly implementation would use a smaller block size and iterate.
    Dim pBlockSize As IPnt
    Set pBlockSize = New DblPnt
    pBlockSize.X = nCol
    pBlockSize.Y = nRow
    Dim pPixelBlock As IPixelBlock
    Set pPixelBlock = pRawPixels.CreatePixelBlock(pBlockSize)
    Dim val
    val = pPixelBlock.SafeArray(0)
    Dim pTinSurf As ITinSurface
    Set pTinSurf = pTin
    Dim pRasterProps As IRasterProps
    Set pRasterProps = pRawPixels
    Dim nodataFloat As Single
    Dim nodataInt As Long
    ' QueryPixelBlock takes an origin representing the upper left cell center.
    ' Calculate that cell center's position here.
    pOrigin.X = pOrigin.X + (cellsize * 0.5)
    pOrigin.Y = pOrigin.Y + (cellsize * nRow) - (cellsize * 0.5)

    If (ePixelType = PT_FLOAT) Then
        nodataFloat = pRasterProps.NoDataValue
        pTinSurf.QueryPixelBlock pOrigin.X, pOrigin.Y, cellsize, cellsize, eRastConvType, nodataFloat, val
    Else
        nodataInt = pRasterProps.NoDataValue
        pTinSurf.QueryPixelBlock pOrigin.X, pOrigin.Y, cellsize, cellsize, eRastConvType, nodataInt, val
    End If

    If pTin.ProcessCancelled Then GoTo Cancel
    Dim pOffset As IPnt
    Set pOffset = New DblPnt
    pOffset.X = 0
    pOffset.Y = 0
    pRawPixels.Write pOffset, pPixelBlock
    ' need this for some reason with temporary integer grids

    If (Not bPerm) And (ePixelType = PT_LONG) Then
        Dim pBand As IRasterBand
        Set pBand = pRawPixels
        Dim pStats As IRasterStatistics
        Set pStats = pBand.Statistics
        pStats.Recalculate
    End If

    If (bPerm) Then
        ' flush edits to disk by freeing all pointers
        Set pRDS = Nothing
        Set pRawPixels = Nothing
        Set pPixelBlock = Nothing
        Set pRasterProps = Nothing
        Set pRDS = OpenRasterDataset(sDir, sName)
    End If

    Set TinToRaster = pRDS
    Exit Function
    Cancel:
    Set TinToRaster = Nothing
End Function

转载于:https://www.cnblogs.com/zany-hui/articles/1768896.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值