Old thread I know - but there is now an easy way in case anyone searching...
arcpy.Extent has a polygon property that neatly returns the extent as a polygon
ex <SPAN class="operator token">=</SPAN> extent<SPAN class="punctuation token">.</SPAN>polygon<SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
Darren,
This code you modified worked well. I did have one other question if possible. The "Polygon_Extent" layer that gets outputted does not contain any fields. Is it possible to incorporate the field that was used to create the Data Driven Pages from (i.e. the index layer) into the outputted layer?
Thanks again
This is exactly what I was looking for. Thank you very much!
You can modify Jake Skinner's code as below to accommodate DDPs (mostly tested):
import arcpy from arcpy import env from arcpy import mapping env.workspace = r"C:\temp\Test.gdb" extents = [] mxd = mapping.MapDocument(r"C:\temp\python\Philadelphia.mxd") for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum dataframe = mapping.ListDataFrames(mxd, "*")[0] frameExtent = dataframe.extent XMAX = frameExtent.XMax XMIN = frameExtent.XMin YMAX = frameExtent.YMax YMIN = frameExtent.YMin pnt1 = arcpy.Point(XMIN, YMIN) pnt2 = arcpy.Point(XMIN, YMAX) pnt3 = arcpy.Point(XMAX, YMAX) pnt4 = arcpy.Point(XMAX, YMIN) array = arcpy.Array() array.add(pnt1) array.add(pnt2) array.add(pnt3) array.add(pnt4) array.add(pnt1) polygon = arcpy.Polygon(array) extents.append(polygon) arcpy.CopyFeatures_management(extents, "Polygon_Extent")
I have been looking for something like this for a little while now and the Python script that was posted here a few years back worked great. Thnaks for that! However, would it be possible to run something like this on multiple pages? I used Data Driven Pages to create several pages and would like a feature class or shapefile of the map extent of all of these pages. I noticed that this script will only output the first page.
Thanks in advance and I appreciate the assistance!
import arcpy from arcpy import env from arcpy import mapping env.workspace = r"C:\temp\Test.gdb" mxd = mapping.MapDocument(r"C:\temp\python\Philadelphia.mxd") dataframe = mapping.ListDataFrames(mxd, "*")[0] frameExtent = dataframe.extent XMAX = frameExtent.XMax XMIN = frameExtent.XMin YMAX = frameExtent.YMax YMIN = frameExtent.YMin pnt1 = arcpy.Point(XMIN, YMIN) pnt2 = arcpy.Point(XMIN, YMAX) pnt3 = arcpy.Point(XMAX, YMAX) pnt4 = arcpy.Point(XMAX, YMIN) array = arcpy.Array() array.add(pnt1) array.add(pnt2) array.add(pnt3) array.add(pnt4) array.add(pnt1) polygon = arcpy.Polygon(array) arcpy.CopyFeatures_management(polygon, "Polygon_Extent")
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.