Ask A Cartographer

Create layer from index polygon

February 02 2011 | 1 comment
Categories: ArcGIS 10, ArcGIS Methods

I'm interested in creating individual polygons from the index layer when using Data Driven Pages. My index layer is towns, and I'd like to use this intersect with point features, so any features within my index town can be made into a feature layer as well as any features outside of my index town. This step will be incorporated into a larger process.

Thank you!

Mapping Center Answer:

This is an update to the answer sent previously.  There are some methods in arcpy.mapping to get the extent of each data driven page. I just need to confirm if there is a python way to create polygons. I hope it is OK if I get back to you next week with a final answer as I need to do a little bit of checking first.

Update posted by Jonathan Quinn on Feb 4 2011 6:22AM
Thank you for getting back to me. Essentially what I'm doing is creating two dynamic lists in a map layout; one for points inside of the index polygon, and one outside of it. I was using Page Definitions to achieve a query on both the index town polygon and the town polygons around it, but it was creating problems with the data.

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Documents and Settings\jquinn\Desktop\Dam Map\newdammap.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
Outlyr = arcpy.mapping.ListLayers(mxd, "Other Dams", df)[0]
cur = arcpy.SearchCursor("Town Index", "", "", "", "")
row =
for pageNum in range(1, 2):
InDamInfo = ""
TownName = ""
InTown = "InTown"
mxd.dataDrivenPages.currentPageID = pageNum
arcpy.SelectLayerByLocation_management("Dams Within Town","INTERSECT","Dams Within Town","#","NEW_SELECTION")
arcpy.MakeFeatureLayer_management("Dams Within Town", InTown)
arcpy.SelectLayerByAttribute_management("Dams Within Town", "CLEAR_SELECTION", "")
cur2 = arcpy.SearchCursor(InTown, "", "", "", "")
row2 =
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if == "In Dams":
while row2:
InDamName = row2.getValue("DAM_NAME")
InDamNo = row2.getValue("DAM_NO")
InDamHaz = row2.getValue("DAM_HAZ")
InDamInfo = InDamInfo + (str(InDamNo)) + " - " + (str(InDamName)) + ", Dam Hazard: " + (str(InDamHaz)) + "\n"
row2 =
elm.text = InDamInfo
OutDamInfo = ""
OutTown = "OutTown"
OutdfAsFeature = arcpy.Polygon(arcpy.Array([df.extent.lowerLeft, df.extent.lowerRight, df.extent.upperRight, df.extent.upperLeft]), df.spatialReference)
arcpy.SelectLayerByLocation_management(Outlyr, "INTERSECT", OutdfAsFeature, "", "NEW_SELECTION")
arcpy.MakeFeatureLayer_management("Other Dams", OutTown)
arcpy.SelectLayerByAttribute_management("Other Dams", "CLEAR_SELECTION", "")
cur3 = arcpy.SearchCursor(OutTown, "", "", "", "")
row3 =
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if == "Out Dams":
while row3:
OutDamName = row3.getValue("DAM_NAME")
OutDamNo = row3.getValue("DAM_NO")
OutDamHaz = row3.getValue("DAM_HAZ")
OutDamInfo = OutDamInfo + (str(OutDamNo)) + " - " + (str(OutDamName)) + ", Dam Hazard: " + (str(OutDamHaz)) + "\n"
row3 =
elm.text = OutDamInfo
TownName = row.getValue("TOWN_INDEX")
arcpy.mapping.ExportToPDF(mxd, r"C:\Documents and Settings\jquinn\Desktop\Dam Map\Maps\\" + TownName + " Map of Dams" + ".pdf")
arcpy.AddMessage('Exported Awesomely')
row =
del mxd, df, Outlyr, cur, row, InDamInfo, OutDamInfo, TownName, cur2, row2, cur3, row3, InDamName, InDamNo, InDamHaz, OutDamName, OutDamNo, OutDamHaz, OutdfAsFeature

There is my script if it helps. I'd like to export the polygon, perform the SelectByAttribute and MakeFeatureLayer function to isolate the Dams in the index polygon, create the table, and then delete both the index town polygon as well as the isolated Dams layer. I hope this clears up any confusion on what I'm doing.

Thank you for checking up on this. No problem if it can't be done; I have modified the script to just put all of the dams in the extent on one list rather than two lists.

If you would like to post a comment, please login.

Contact Us | Legal | Privacy |