Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Adding a variable and loop

$
0
0
I am python beginner! I need to select a specific polygon (one grid of our locator sheets) then select and clip all the storm main on that sheet and sum the total length of those mains. I created the following code which works and gives me the expected values but I need to do this for about 350 map sheets. How do I pass the value (in this case 'J-21') from the field in the feature and create a loop to cursor thru all the individual map sheets (polygons)? I also need to add the sheet number to the name of the output table. Thanks.

Deb Wilson

Code:

# ---------------------------------------------------------------------------
# storm_main_by_loc_length.py
# Created on: 2013-08-14 09:05:36.00000
# By Deborah Wilson
# Description: Select Storm Mains by individual locator sheets and sum length
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
mxd = arcpy.mapping.MapDocument ("CURRENT")

# Local variables:
Locator_Grid = "Locator Grid"
Storm_Mains = "Storm Network\\Storm Mains"
loc_polygon_Select2 = "C:\\Documents and Settings\\dwilson\\My Documents\\ArcGIS\\Default.gdb\\loc_polygon_Select2"
loc_polygon_Select2_Intersec = "C:\\Documents and Settings\\dwilson\\My Documents\\ArcGIS\\Default.gdb\\loc_polygon_Select2_Intersec"
loc_polygon_Select2_Intersec1 = "C:\\Documents and Settings\\dwilson\\My Documents\\ArcGIS\\Default.gdb\\loc_polygon_Select2_Intersec1"

# Process: Select
arcpy.Select_analysis(Locator_Grid, loc_polygon_Select2, "N_LOC = 'J-21'")

# Process: Intersect
arcpy.Intersect_analysis("'C:\\Documents and Settings\\dwilson\\My Documents\\ArcGIS\\Default.gdb\\loc_polygon_Select2' #;'Storm Network\\Storm Mains' #", loc_polygon_Select2_Intersec, "ALL", "", "INPUT")

# Process: Summary Statistics
arcpy.Statistics_analysis(loc_polygon_Select2_Intersec, loc_polygon_Select2_Intersec1, "SHAPE_Length SUM", "")


Viewing all articles
Browse latest Browse all 2485

Trending Articles