I want to determine the coordinates of my current data frame. To do so I wrote this script:

def DataFrame ():

  mxd = arcpy.mapping.MapDocument("CURRENT") 
  df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
  return mxd,df

def Center (df):

  extent = df.extent 
  xmin = extent.XMin
  xmax = extent.XMax
  ymin = extent.YMin
  ymax = extent.YMax

  x = xmax - ((xmax - xmin)/2)
  y = ymax - ((ymax - ymin)/2)
  return x,y

As long as I am working with a geographic coordinate system, the results will be exactly the longitude and latitude. But as soon as I have a projected coordinate system it will return map units (i.e. meters). How can I avoid that problem? I always need to get lon/lat independend on the maps projection.

  • 1
    Have you looked at the Convert Coordinate Notation tool?
    – PolyGeo
    Aug 9, 2013 at 9:56
  • Hmm, as far as I understand it right, this would mean that I have to create tables for the values that can then be converted. I was hoping that there is a much easier way like just using "arcpy.convertCoordinates" or something.
    – Gideon
    Aug 9, 2013 at 10:07

1 Answer 1


Try using the projectAs function available on your Extent object:

extent_geographic = df.extent.projectAs(arcpy.SpatialReference(4326)) # GCS_WGS_1984
  • That was exactly what I was looking for. Thank you very much! Works perfectly.
    – Gideon
    Aug 9, 2013 at 11:05
  • I thought there was an easier way.
    – PolyGeo
    Aug 9, 2013 at 12:13
  • Ok, now I am feeling dumb. When I tried it some hours ago, it worked in my script and also in the python window. Now I tried again and suddenly I get the Error message: "Runtime error <type 'exceptions.AttributeError'>: 'Extent' object has no attribute 'projectAs'".
    – Gideon
    Aug 9, 2013 at 13:19
  • That's strange. See if you can reproduce it and send it to ESRI as a bug report. I would get a different error if I tried to use arcpy.SpatialReference("GCS_WGS_1984") -- for some reason it didn't like that but the SRID worked fine.
    – blah238
    Aug 9, 2013 at 17:11

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.