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 need help! I am writing a program that will look through the table of a station layer and then go to the annotation layer and list all the missing values. For Example: The station layer has a field called TFLAG which has the station id in it. The annotation layer has a field called TFLAG with the same station id in it. I want to look through the annotation layer and find all the missing values that the station layer has that the annotation layer is missing. I have written some code. I need to know if I am headed in the right direction!!

import arcpy, os, sys, string
arcpy.env.overwriteOutput = True
fc = "K:\TASS\4_MAPPING_DATA_SUPPORT\Traffic_Mapping\Traffic_Count_Data\2011_Counts\2011_Annual_Stations\Final_Annual_Stations_2012.shp"
fields = ("TFLAG", "T_FLAG")
Value = "TFLAG" <> "T_FLAG"
where = "%s = '%s'" % (field, vlaue)
dhList = []
for w in ws:
    arcpy.env.workspace = w
    gdb = arcpy.ListWorkspaces ("*", "TFLAG")
    for fc in gdb:
        arcpy.env.workspace = fc
share|improve this question

1 Answer 1

I'd do something more like the below. Note that there certainly are more "Pythonic" approaches; however, this should get you through the problem.

Basically I just create two lists of station id's, then compare them. The first list is the comprehensive one from your master file, with 100% of the id's you're checking for. And the second list is build against your annotations table. In the last action, I loop over the comprehensive list and check to see if that id appears in annos/reduced list. If the id is NOT found, I print it to the screen. ..if you have tons of these missing id's you might need to write them into a .txt file, but if you just have a few dozen, dumping to the screen should suffice.

(Fair warning! I don't have Arc 10 so I can't test this, but I think the approach should be passable. I hope it helps.)

[Edited to accommodate Arc 10.0 and up.]

import arcpy, os, sys, string
# These imports are probably a bit excessive but I left them as-is.

# Access the comprehensive Feature Class and build a list of id's.
stationsFC = "K:\TASS\4_MAPPING_DATA_SUPPORT\Traffic_Mapping\Traffic_Count_Data\2011_Counts\2011_Annual_Stations\Final_Annual_Stations_2012.shp"

allStationIds = []
for row in arcpy.SearchCursor(stationsFC, "", "", "TFLAG")
    allStationIds.append(str(row.getValue("TFLAG")))


# Next, access your annos table and build a list of those id's.
# Obviously, you'll need to fix this! But here's another way
# to get into your data if it's in a geodatabase..
annosFC = "c:/Path_To_Your_Data/gisGeoDB.gdb/stationAnnos"

allAnnoStations = []
for row in arcpy.SearchCursor(annosFC, "", "", "TFLAG")
    allAnnoStations.append(str(row.getValue("TFLAG")))


# Finally, loop over the master list, and test each value to learn
# whether it appears among the annotations.
for stationId in allStationIds:
    if not stationId in allAnnoStations:
        print("Missing station: " + str(stationId))
share|improve this answer
    
up vote for comment lines! –  Geocurious Apr 18 '13 at 17:52
    
I am getting an exception raised. But I can't get it to highlight the row it has trouble with. I've tried toggle breakpoint and then step over. What else should I try? –  Michelle Couden Apr 19 '13 at 19:09
    
When I run it in ArcMAP Python window, it says object has no attribute 'da'. –  Michelle Couden Apr 19 '13 at 19:11
1  
@elrobis, the arcpy.da module was added at 10.1. –  blah238 Apr 19 '13 at 21:25
1  
No, I think you would need to use getValue to get the value of the field, as regular SearchCursor row objects are different from da.SearchCursor row objects (which are actually tuples): Compare help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… (10.0) vs. resources.arcgis.com/en/help/main/10.1/index.html#//… (10.1). It is unfortunate that they do not highlight the usage differences. –  blah238 Apr 19 '13 at 21:37

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.