Select to view content in your preferred language

Selecting a Feature then Processing

1160
3
01-10-2011 07:49 AM
BradOleson
Emerging Contributor
I am a Python newbie, though have other programming experience.  I am looking to run through a set of features one at a time and process a union with another layer.  There are better than 1000 features, so automating this is the only practical way.  Can someone slip me some python code that would allow this, or point me to a better resource?  Thanks!
Tags (2)
0 Kudos
3 Replies
ChrisMathers
Deactivated User
Well you want to iterate over the feature class using a cursor.

cursor=arcpy.SearchCursor(feature class path or layer object)
for feature in cursor:
    SelectLayerByAttribute(feature class, feature.OID)
    arcpy.Union(union params here)


Thats kinda meta but is the way i would do it. It will give you a feature class for every feature doing it this way so you would have 1000+ new feature classes. Could you copy all the features into one feature class and merge them? That would give you similar results without so much output.

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Cursor/000v00000068000000/
0 Kudos
BradOleson
Emerging Contributor
Thanks!  I found a way in Model Builder to do what I was looking for, but your guidance likely will help in future needs as I will be porting my knowledge over to Python.  I appreciate your input!

Brad
0 Kudos
KimOllivier
Honored Contributor
Seeing a geoprocessing tool inside a cursor always gives me the shivers. This looks like reinventing GIS in a Python script with an unnecessary loop. Maybe like emptying the ocean with a thimble.

It surely will be very very slow calling union for a thousand separate features, and I have trouble understanding the need to do this. ArcGIS is a geo-relational system, at least it was before ArcObjects. The mindset is to find a tool that processes the whole dataset with an implied loop over the whole featureclass.

Try to think of a problem in the same way as an SQL query. You don't usually open a cursor there.

If the sources are suitably tagged, then a union between the two featureclasses will do all the unions in one step without a cursor.
0 Kudos