I have two shapefiles that contain position information for individuals, one is their reported location (line segments) and the other is their high-frequency recorded location (point data); they have an ID field that is common between them. What I am looking to do is identify the reported locations in the larger recorded data set with a spatial selection. The problem is my data is so condensed that I cannot do a simple select by location. There is too much overlap of individual locations. I also have over 1,000 individual IDs so I don't want to individually query each ID.
What I am looking for is a way to use possibly a cursor to go through each unique ID, query only the records in each table that share that ID, then do the spatial selection. I am very new to cursors and scripting in general so I don't know if a cursor can be used for two tables. (This may be irrelevant but for this process I can convert my line data to point data if having the same type of shapefiles is important.)
(Removed previous code that I am no longer using)
I am also unaware if maybe Make Query Table will work for this (I have never used it).
UPDATE: Here is a new code that I worked on with a fellow GIS person. GOOD NEWS! After leaving ArcGIS alone for a while, my code ran! It went as expected, but only did one iteration on one ID. The iteration should be implied in the Cursor as far as I know, or is there a line of code I'm missing that tells the Cursor to repeat for all IDs?
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_management("hmb2009", "SUBSET_SELECTION", ' "trip_id" = ' + str(row.trip_id)) arcpy.CalculateField_management("hmb2009", "match_activity", 1) arcpy.SelectLayerByAttribute_management("hmb2009", "CLEAR_SELECTION") arcpy.Delete_management("currentLines") del row, rows
UPDATE 2: So I have troubleshooted, and the reason the code only ran once is this error associated with my Make Feature Layer tool. Here is the error message: ERROR 000622: Failed to execute (Make Feature Layer). Parameters are not valid. ERROR 000628: Cannot set input into parameter in_features.
I tried putting the full address into that tool (only that one) instead of referencing the layer in the map and it works!
Thanks so much everyone!