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
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.