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.
Answer
Try using the projectAs
function available on your Extent
object:
extent_geographic = df.extent.projectAs(arcpy.SpatialReference(4326)) # GCS_WGS_1984
No comments:
Post a Comment