Select to view content in your preferred language

Data Frame Coordinates

595
1
09-01-2011 04:56 PM
PatrickFischer1
Deactivated User
Hi everyone, sorry if this is in the wrong thread but i'm not quite sure where to post this. I need some help with a problem i'm trying to solve. Here is my situation; I am trying to pull the x1, x2, y1, and y2 coordinates from my data frame, create a feature class from that and automatically edit those fields with input from the user. I looked around the site a bit before posting, and found something about Image Rectangle which looks promising but my skills in C are not quite up to par to code something for ArcGIS. I am using ArcGIS 10.0 and i'm not to familiar with all the new tools from 9.3.1 yet and I didn't see any tools that would allow me to do this. Is there an easy way to do this rather than going in and doing this manually for every mxd I have? (300-400 mxds)

Any response or help is greatly appreciated.
0 Kudos
1 Reply
BenjaminGale
Occasional Contributor
I think you can do this with python. The script below will take the coordinates from the 1st data frame in a mxd (in the units of the frame's coordinate system) and create a polygon out of it.
I made it store the x, y values in the attribute table too. Again the values will be in the frame's coord. system units.

I imagine you'll probably want to make it loop through multiple mxds since you have so many.
I wasn't sure of some of your specifics or exactly what you wanted the user to input so I thought I'd leave it at the example below for now.

Hope it helps : )

import arcpy

#Input
inMXD = "FILEPATH" #PLACE HOLDER
outFeature = "FILEPATH" #PLACE HOLDER

#Set MXD and (first) Dataframe
mxd = arcpy.mapping.MapDocument(inMXD)
df = arcpy.mapping.ListDataFrames(mxd)[0]

#Set default output Coordinate System to the same values as the dataframe.
arcpy.env.outputCoordinateSystem = df.spatialReference

#Initial Variables
point = arcpy.Point()
array = arcpy.Array()

#Get data frame bounding values 
dfxMax = df.extent.XMax
dfxMin = df.extent.XMin
dfyMax = df.extent.YMax
dfyMin = df.extent.YMin

#Create list of coordinates
coordList = [[dfxMin,dfyMin],[dfxMax,dfyMin],[dfxMax,dfyMax],[dfxMin,dfyMax]]

for coordPair in coordList:
    point.X = coordPair[0]
    point.Y = coordPair[1]
    array.add(point)

#Re-add first point to array to close polygon
array.add(array.getObject(0))

#Create Polygon
polygon = arcpy.Polygon(array,df.spatialReference)

#Creature Feature
arcpy.CopyFeatures_management(polygon, outFeature)

#Add fields for calculated x and y values
coords = [dfxMax, dfxMin, dfyMax, dfyMin]
fieldNames = ["xMax","xMin","yMax","yMin"]
i = 0
for fieldName in fieldNames:
    arcpy.AddField_management(outFeature, fieldName, "DOUBLE")
    arcpy.CalculateField_management(outFeature, fieldName, coords)
    i = i + 1
0 Kudos