Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am comparing fields in layers. I have the AADT layer and AADTAnno layer and I want it to search the fields FLAG and TFLAG. For Example: If there is a 29C9 in AADT layer in FLAG fields then there needs to be the same thing in the ANNo layer in the TFLAG field. My code stops running on my for row in FRows command line. I think its because I'm not letting it know that FLAG is the field. Please help!!

New Code!!

import arcpy, traceback

mxd = arcpy.mapping.MapDocument(r"K:\TASS\2 - GEO-DATA PROCESSING SUPPORT\MICHELLE'S WORK_ENTER NOT!!\Work Folder\Python Programming\Wayne's Tools\Abilene_Base_Map.mxd")
lstLayers = arcpy.mapping.ListLayers(mxd)

flayer = arcpy.mapping.ListLayers(mxd, "AADT")[0]
alayer = arcpy.mapping.ListLayers(mxd, "AADTAnnoLabel")[0]

FRows = arcpy.SearchCursor(flayer)
ARows = arcpy.SearchCursor(alayer)

ffields = arcpy.ListFields(flayer, "", "FLAG")
afields = arcpy.ListFields(alayer, "", "TFLAG")

FList = []
AList = []

for row in FRows:
    Fvalue = row.getValue("FLAG")
    FList.append(str(Fvalue))

for row in ARows:
    Avalue = row.getValue("TFLAG")
    AList.append(str(Avalue))

matched = set(FList) & set(AList)

for x in matched:
    exp = "ID = " + x
    arcpy.SelectLayerByAttribute_management(flayer, "ADD_TO_SELECTION", exp)
    arcpy.SelectLayerByAttribute_management(flayer, "SWTCH_SELECTION")
share|improve this question
8  
lol is this file path for real? 'K:\TASS\2 - GEO-DATA PROCESSING SUPPORT\MICHELLE'S WORK_ENTER NOT!!\Work Folder\Python Programming\Wayne's Tools\Abilene_Base_Map.mxd' –  elrobis Apr 25 '13 at 19:35
    
What error do you get? –  blah238 Apr 25 '13 at 19:48
    
@blah238 Yes, it is. My boss wanted us to make sure people know what folder to not get into. LOL I actually fixed the Listfields problem. My row in FRows command line is still not working. I'm thinking it's missing an IF. When I add the script tool to a toolbox in ArcMAP with no parameters. I get Error:999999???? –  Michelle Couden Apr 25 '13 at 20:16
    
Does the FLAG field actually exist in the feature class referenced by flayer? I also get a 999999 error if I refer to a nonexistent field in the argument to getValue. –  blah238 Apr 25 '13 at 20:21
    
So you want to compare FLAG and TFLAG values which are found in separate tables? What do you want to do if a FLAG value is missing from TFLAG? Add it to your Anno layer? I'm sensing a while loop might be necessary here... –  Patty Jula Apr 25 '13 at 21:11

1 Answer 1

You have a typo/logic error in your second for loop. You reference row, but define rows as the iteration variable. By the time row is referenced it is out of scope. Presumably you should be getting a NameError with the relevant information to confirm this.

Also your exp expression looks invalid. There should be DBMS-specific delimiters around the field name (ID). Take a look at this answer: How do I include a variable in the where clause of arcpy.Select_analysis?

share|improve this answer
    
So, to fix this would I also reference the field in the same area and then add an IF statement?import arcpy, traceback FRows = arcpy.SearchCursor(flayer) ARows = arcpy.SearchCursor(alayer) ffields = arcpy.ListFields(flayer, "", "FLAG") afields = arcpy.ListFields(alayer, "", "TFLAG") FList = [] AList = [] for row in FRows: for field in ffields: Fvalue = row.getValue("FLAG") FList.append(str(Fvalue)) for row in ARows: for field in afields: Avalue = row.getValue("TFLAG") AList.append(str(Avalue)) –  Michelle Couden Apr 25 '13 at 20:22
    
No, you would fix the typo. Change rows to row. –  blah238 Apr 25 '13 at 20:24
    
Now, I got it to get at least down to the SelectLayerByAttribute line. It's giving me an invalid expression. So I have that line of code typed out wrong right? –  Michelle Couden Apr 25 '13 at 20:26
2  
Please do not use the comments to put code. Edit your question instead. –  blah238 Apr 25 '13 at 20:29
    
I looked on Desktop Help and it looks like I have the SelectLayer typed right. I'm not understanding what I'm missing. –  Michelle Couden Apr 25 '13 at 20:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.