Select to view content in your preferred language

$$NCOLS + $$ROWMAP

7111
5
Jump to solution
01-20-2012 05:44 PM
YongTian
New Contributor
How do we implement $$NCOLS + $$ROWMAP in map calculator? I would appreciate any advice. My email: yong.q.tian@gmail.com
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

Here's an implementation of   William Huber's neat idea of using the FlowAccumulation tool to generate xmap and  ymap. This uses the current processing environment, it will generate an error if the arcpy.env.extent or cellSize are not explicitly set.

(this code has a bug fixed - thanks Cameron!

from arcpy.sa import *
from arcpy import env as E
# Calculate $$NROWS and $$NCOLS from current environment
cellSize = float(E.cellSize)
nrows = int((E.extent.YMax - E.extent.YMin) / float(E.cellSize))
ncols = int((E.extent.XMax - E.extent.XMin)  / float(E.cellSize))
# Bill Huber's method for $$XMAP and $$YMAP: "1" flows "right", "64" (63+1) flows "up"
tmpg = CreateConstantRaster(1)
xmap = (FlowAccumulation(tmpg) + 0.5) * cellSize + E.extent.XMin
ymap = (FlowAccumulation(tmpg + 63) + 0.5) * cellSize + E.extent.YMin
# applying the same method for $$ROWMAP and $$COLMAP
colmap = Int(FlowAccumulation(tmpg))
rowmap = Int(FlowAccumulation(tmpg + 3))  # flowdir "4" is "down" (top row is 0)

View solution in original post

5 Replies
ChrisSnyder
Honored Contributor
Unsuported in new v10.0 Map Algebra! Although you can get $$NCOLS through the describe property in Python or the GetRasterProperties toolbox tool.

See: https://c.na1.visual.force.com/apex/ideaView?id=087300000008DT2AAM#comments

You can still use the good ole' Map Algebra sytax in v10 though:

arcpy.gp.SingleOutputMapAlgebra_sa(blah, blah)
CameronScott
New Contributor
Thanks for this! I'm new to both rasters and Python so code like this is a HUGE help. However, I think there's a small bug.

Shouldn't the xmap setting be adding XMin instead of YMin at the end? I.e.,
xmap = (FlowAccumulation(tmpg) + 0.5) * cellSize + E.extent.XMin

Thanks again for the code, very useful.
curtvprice
MVP Esteemed Contributor

Here's an implementation of   William Huber's neat idea of using the FlowAccumulation tool to generate xmap and  ymap. This uses the current processing environment, it will generate an error if the arcpy.env.extent or cellSize are not explicitly set.

(this code has a bug fixed - thanks Cameron!

from arcpy.sa import *
from arcpy import env as E
# Calculate $$NROWS and $$NCOLS from current environment
cellSize = float(E.cellSize)
nrows = int((E.extent.YMax - E.extent.YMin) / float(E.cellSize))
ncols = int((E.extent.XMax - E.extent.XMin)  / float(E.cellSize))
# Bill Huber's method for $$XMAP and $$YMAP: "1" flows "right", "64" (63+1) flows "up"
tmpg = CreateConstantRaster(1)
xmap = (FlowAccumulation(tmpg) + 0.5) * cellSize + E.extent.XMin
ymap = (FlowAccumulation(tmpg + 63) + 0.5) * cellSize + E.extent.YMin
# applying the same method for $$ROWMAP and $$COLMAP
colmap = Int(FlowAccumulation(tmpg))
rowmap = Int(FlowAccumulation(tmpg + 3))  # flowdir "4" is "down" (top row is 0)
XanderBakker
Esri Esteemed Contributor

It's always cool to see some of William Huber‌ ideas revive!

Thanx for sharing Curtis Price

curtvprice
MVP Esteemed Contributor

No problem, I was just resurrecting some old posts of mine, getting them tagged and placed in GeoNet where they will be easier to find.