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?

  • 1
    marika, you can convert your raster to points and than use the x and y of each point representing each raster cell.
    – Gorgens
    Commented Mar 13, 2015 at 15:57
  • Another option is to export your raster as asc and use the coordinates reference and the pixel size to get all your cells.
    – Gorgens
    Commented Mar 13, 2015 at 15:58
  • 1
    The coordinate boundary (ulx/uly/lrx/lry) is a property of any raster. Coordinate location not generally seen as a property of individual cells, per se, since such an extraction would increase the size manifold. What are you going to do with this information, and in what programming language?
    – Vince
    Commented Mar 13, 2015 at 16:01
  • I want to use latitude and longitude as explanatory variables in a multiple regression model. I will use R. Commented Mar 13, 2015 at 16:16
  • read the dem with raster() and use functions coordinates, xFromCol, yFromRow, xyFromCell etc.
    – mdsumner
    Commented Mar 13, 2015 at 19:50

3 Answers 3


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  

#you need to set appropriate extent and cellsize gp environments
result=gp.SingleOutputMapAlgebra('$$XMAP', xmap)  
result=gp.SingleOutputMapAlgebra('$$YMAP', ymap)  
  • In the first example, what the (1) and (64) stand for?
    – NewAtGis
    Commented Jun 4, 2015 at 16:59
  • @NewAtGis They are direction constants/codes. See the help - resources.arcgis.com/en/help/main/10.1/index.html#/…
    – user2856
    Commented Jun 5, 2015 at 3:03
  • thanks @Luke. I got the FlowAcc rasters, but I do not know how to put to work that formula in the RasterCalculator. I mean, I have read the arcGIS documentation, and I got the idea of the direction codes. But, once I got the FlowAcc rasters, there is some other step to take before using the formula?
    – NewAtGis
    Commented Jun 5, 2015 at 7:31
  • @NewAtGis You don't need to create flow accumulation rasters. Just open the raster calculator, set your environment (extent, snap raster and cell size) appropriately and enter the expression. ie (FlowAccumulation(1) + 0.5)* cellsize + xmin substituting cell size and xmin with the actual values.
    – user2856
    Commented Jun 5, 2015 at 9:22
  • Thanks @Luke. I have circumvented the problem, as I described here: gis.stackexchange.com/questions/149736/…
    – NewAtGis
    Commented Jun 5, 2015 at 9:31

Another approach with R

r <- raster('dem.tif')
lon <- init(r, 'x', filename='lon.tif')
lat <- init(r, 'y', filename='lat.tif')
  • Your "another approach with R" was not tested. It doesn't work. See my "Editing Note 2".
    – xunilk
    Commented Mar 18, 2015 at 9:35
  • That probably means that you are using an old version of R/raster. Commented Mar 19, 2015 at 15:59

In 'Raster Calculator' tool ArcGIS (Desktop or Pro)


"Raster" --> Is your reference raster

LongitudeRaster =


LatitudeRaster =


Just to confirm, Compare minimum and maximum statistics and extent in the Raster results in information raster properties.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.