阅读:925回复:0
如何获得raster数据上当前点的行和列
问:col&row of a point in a feature layer over a raster
I have a map with a raster layer and a feature layer with one or more points. How can I get the col&row number of each of the points as if they were rasterized with the cell size of the raster layer? Thanks 答:Here's a portion of some code I wrote to do just that...I was searching based upon a kernel size but this will get you the row,col info based upon point location. The code shown assumes you've already grabbed a feature and already have a ref to an IRasterBand obj. Dim pRaster As IRaster 168: Set pRaster = m_pRasLayer.Raster 'this is a mod level raster layer that I grabbed elsewhere...you could simply grab it from the map Dim pRasAnalProps As IRasterAnalysisProps 170: Set pRasAnalProps = pRaster Dim dPixHeight, dPixWidth As Double 172: dPixHeight = pRasAnalProps.PixelHeight 173: dPixWidth = pRasAnalProps.PixelWidth 'We'll need the only existing band of a single band raster Dim pRasBandCol As IRasterBandCollection Set pRasBandCol = m_pRasLayer.Raster 'this is a mod level raster layer that I grabbed elsewhere...you could simply grab it from the map Dim pRasBand As IRasterBand Set pRasBand = pRasBandCol.Item(0) Dim pRasProps As IRasterProps Set pRasProps = pRasBand Dim pEnv As IEnvelope Set pEnv = pRasProps.Extent Dim dXDist, dYDist As Double Dim lRow, lColumn, lStartRow, lStartColumn As Long Dim pPoint As IPoint 'Initialize search location in the image Set pPoint = pFeat.Shape 'Make a point from the feature location dXDist = Abs(pPoint.x - pEnv.XMin) 'Create X distance across image dYDist = Abs(pEnv.YMax - pPoint.Y) 'Create Y distance across image If (dYDist / dPixHeight) > Int(dYDist / dPixHeight) Then lRow = Int(dYDist / dPixHeight) + 1 Else lRow = Int(dYDist / dPixHeight) 'Get row of kernel center point End If If (dXDist / dPixWidth) > Int(dXDist / dPixWidth) Then lColumn = Int(dXDist / dPixWidth) + 1 Else lColumn = Int(dXDist / dPixWidth) 'Get column of kernel center point End If |
|