deleted-user-De598MZ4-kwO

Found:  Method for getting $$rowmap, $xmap, etc. for rasters

Discussion created by deleted-user-De598MZ4-kwO on Dec 2, 2011
Latest reply on Dec 2, 2011 by curtvprice
Here is a straightforward method for getting the row and column numbers for rasters.  It also will work for getting the X and Y coordinates.  I had been working with the numpy.indices to get the row and column numbers, but for large rasters (10000-by-10000 or larger on my computer), numpy doesn't work because of memory errors.

This method should work for rasters of any size and is reasonably fast.  It runs in a couple of seconds for a 2000-by-2000 raster, and in about 20 seconds for a 10000-by-10000 raster.

The sample code below returns Column number and X-Coord.  The Row and Y-Coord can be obtained with similar commands.

This answers some of the issues that I posted in this forum a couple of days ago as "Problems with large rasters: $$rowmap, numpy, Memory Error, and numeric precision."

I don't know much about posting, so hopefully the lines below will show up in a code block.  Regards, Tim.L

import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension('spatial')
#
env.workspace = 'c:/workspace'
InRasPath = 'pathnameforrastergoeshere'
#
env.extent = InRasPath
env.cellSize = InRasPath
xcell = float(env.cellSize)
x1 = env.extent.XMin
y1 = env.extent.YMin
x2 = env.extent.XMax
y2 = env.extent.YMax
#
# Create temporary points and line as needed.
myPoint1 = arcpy.Point(x1,y1)
myPoint2 = arcpy.Point(x1,y2)
myArray = arcpy.Array()
myArray.add(myPoint1)
myArray.add(myPoint2)
myLine = arcpy.Polyline(myArray)
#
# EucDistance returns distance from line to edge of each cell.
myDistRas = EucDistance(myLine,(x2 - x1))
#
# Returns x-coordinate for centroid of the cell.
XCoord = myDistRas + x1 + xcell / 2.
#
# Returns column number as integer ranging from 1 to num-cols.
XCol = Int(myDistRas / xcell + 1.01)
#
del [myPoint1,myPoint2,myArray,myLine,myDistRas]

Outcomes