I am trying to do the same thing, and I am new to Python so am looking for some input on this script I am trying to run.
Using ArcGIS 9.3.1, I have a shapefile of index grids in shapefile format with a text field called [NAME] that contains a UID for each grid (ie, Grid-1, Grid-2, etc...)
I would like to clip the lines to these grids with a subset of lines for each grid.
Below is my script thus far (also attached as .py Clip_wCursor.py and shapefiles with directories are in .7z gis.7z file):
Code:
# ---------------------------------------------------------------------------
# Clip_wCursor.py
# Created for ArcGIS 9.3.1
# (clip generated by ArcGIS/ModelBuilder)
# Attempted cursor mods by a newb, Donovan
# ---------------------------------------------------------------------------
# Import system modules
import sys, string, os, arcgisscripting
# Create the Geoprocessor object
gp = arcgisscripting.create()
# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")
# assign variables...
grids = "C:\\gis\\data\\grids.shp"
lines = "C:\\gis\\data\\lines.shp"
rows = gp.SearchCursor(grids)
row = rows.Next()
feat = row.Shape
for row in rows:
gname = str(row.NAME)
Output = "grd" + "_" + gname + ".shp"
# Process: Clip...
gp.Clip_analysis(lines, feat, Output, "")
I encounter the error:
Code:
Traceback (most recent call last):
File "C:\gis\script\Clip_wCursor.py", line 23, in <module>
for row in rows:
TypeError: 'geoprocessing cursor object' object is not iterable
Is it because I have incorrectly defined my row variable?
Bookmarks