Setting query loop in ModelBuilder/ArcPy?

المشرف العام

Administrator
طاقم الإدارة
I am looking to apply a Select By Location protocol to my data, but need to first query individual IDs in my target and source layer (the same ID in each table, one at a time). How do I loop through a query? I have far too many IDs to manually set a query in each table then perform the selection.

Is there a way to create a looping model (with parameters) or script that will systematically select each (matching) ID in my target and source layers then perform the tools I specify?

I have used the Iterate Feature Selection tool in ModelBuilder to select by ID field in my target layer, but ModelBuilder will not let me have two iterators in the model (even if I could, there is no way to guarantee the iterators are selecting the same IDs at the same time). I have tried linking the Value output of the iterator to a Select by Attribute tool for my source layer but the value can only be set as the whole expression, not part of it.
So I am nearly there.



After extensive discussion with Roy this is the code I've come up with. Unfortunately, while no errors pop up when I run it, nothing actually happens. The process is marked as completely immediately after I run it and nothing has changed. Any thoughts?

rows = arcpy.SearchCursor("hmb_logbook_2009")for row in rows: whereClause = '"trip_id" = ' + str(row.trip_id) arcpy.MakeFeatureLayer_management("hmb_logbook_2009", "currentLines", whereClause) arcpy.SelectLayerByLocation_management("hmb2009", "WITHIN_A_DISTANCE", "currentLines", "1 Miles", "NEW_SELECTION") arcpy.SelectLayerByAttribute_managemet("hmb2009", "SUBSET_SELECTION", ' "trip_id" = ' + str(row.trip_id)) arcpy.CalculateField_management("hmb2009", "match_activity", 1) arcpy.SelectLayerByAttribute_managemet("hmb2009", "CLEAR_SELECTION") arcpy.Delete_management("currentLines")del row, rows

أكثر...
 
أعلى