This is kind of from memory as I cannot access my specific code… I am using 10.3.1 and this will be run inside ArcMap.
Overall goal: Find which layers in my active dataframe intersect a specific layer in the dataframe, then for each unique layer name that intersects the specific layer, output a line of text to a text file (don't need help with that part). I need to do this 5 times, each with a different intersecting layer. The dataframe will have on average 20 layers but in very rare circumstances could have up to 90 or so layers. The list of possible layers present will almost always be the same, however if the layer is empty it will not be present in the dataframe (for context in case that helps).
So, for the SelectLayerByLocation part for the first run of the tool - I think this code will accomplish that (I’ve already imported arcpy and set the workspace etc, my intersect layers are defined elsewhere in the code but I showed it again here so as not to confuse)
mxd = arcpy.mapping.MapDocument("CURRENT") df = mxd.ActiveDataFrame intersectlayer = “Layer 1” layerlist = arcpy.mapping.ListLayers(df) for layer in layerlist: if layer.name != intersectlayer arcpy.SelectLayerByLocation_management(layer, "INTERSECT", intersectlayer)
(Can I add more layer names to the “if layer.name != intersectlayer” line to weed out some returns? Or will that not matter too much in terms of efficiency?)
I am stuck on how to take the results of this query, remove the duplicate layer names (because I’m sure intersectlayer will overlap another layer multiple times) or conversely keep only unique layer names, and then pass the unique layer names with no duplicates to the part of the code where the output text is written…. Is it possible to get the results of the query, and if a result is also in the layerlist then print the message? Not sure how to accomplish that if it's possible...
A suggestion was to
getcount but that result will always be > 0 because
intersectlayer would not exist if it didn't intersect anything (this is covered in an earlier part of the script that I didn't show here).
For additional context: if intersectlayer intersects Marsh once or multiple times, I’ll print one message “Marsh is wet” and so forth with nested
If statements. I've written this code separately and it works as expected as far as I can tell - I am not requesting help with this part of the task (yet), just providing it for context.