[GIS] Getting latitude and longitude raster from DEM using ArcGIS Desktop

arcgis-10.2arcgis-desktoparcmaplatitude longitudespatial-analyst

Could anyone provide with a way to calculate latitude and longitude from DEM, for each raster cell?

In previous posts about this, I have seen that some suggest calculating lat and long in certain sample point locations. This doesn't work for me, as I need complete rasters.

Also, I use ArcGIS 10.2 version so $$XMAP, $$YMAP does not work for me.

Is there any other way inside ArcGIS to get lat and long?

Best Answer

Per Bill Huber's (whuber) clever workaround:

xmap = (FlowAccumulation(1) + 0.5)*cellsize + xmin

ymap = (FlowAccumulation(64) + 0.5)*cellsize + ymin

Curtis Price has developed a python script to do this:

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) 

You can also still use $$XMAP/$$YMAP in ArcGIS 10+ by using the old arcgisscripting API

import arcgisscripting  
gp = arcgisscripting.create(9.3) #This works in ArcGIS 10  
xmap='path/to/output'
ymap='path/to/output'

#you need to set appropriate extent and cellsize gp environments
result=gp.SingleOutputMapAlgebra('$$XMAP', xmap)  
result=gp.SingleOutputMapAlgebra('$$YMAP', ymap)