Have an "AddJoin" that results in no shared records, which is not what I'm expecting. Is it because I'm using a text field for the join? Something else? I'm trying to do this on point features from featureclass layers in a file gdb and a shapefile (both expressed as TableViews) on which I've performed a arcpy.SelectLayerByAttribute_management(). No cursors are being used.

Thanks for any ideas. ArcGIS 10.0. Also, ArcMap crashes if I try a JoinField on the same fields.

>>> arcpy.GetCount_management("GagesII")
<Result '1'>
>>> for row in arcpy.SearchCursor("GagesII"):
...     gageid=row.getValue("GAGE_ID")
>>> gageid
>>> arcpy.GetCount_management("StreamGageEvent")
<Result '1'>
>>> for row in arcpy.SearchCursor("StreamGageEvent"):
...     sourcefea=row.getValue("SOURCE_FEA")
>>> sourcefea
>>> if gageid==sourcefea:
...     print 'yes'
>>> arcpy.AddJoin_management("GagesII", 'GAGE_ID', "StreamGageEvent", "SOURCE_FEA", "KEEP_COMMON")
<Result 'GagesII'>
>>> arcpy.GetCount_management("GagesII")
<Result '-1'>

migrated from stackoverflow.com Apr 24 '13 at 0:37

This question came from our site for professional and enthusiast programmers.

  • Are you doing any Field Info modifications when you create your table views? Especially to the join fields? – blord-castillo Apr 24 '13 at 19:08

You say:

ArcMap crashes if I try a JoinField on the same fields

My feeling is that if it cannot be done interactively then the issue is outside of ArcPy and you should look more closely at your data.

Perhaps try working on fresh copies of your feature class and shapefile and see whether they can be joined both via the layer's context menu (which will give you an option to validate the join) and the Join Field tool.

  • Thanks for that. Your comment made me realize that I had not validated this interactively. I have now tried it interactively without subsetting (arcpy.SelectLayerByAttribute_management()) and it did work. I'm thinking that the problem is related to using a subset selection as part of the AddJoin. I'll try to avoid this by applying my filter criteria as part of the arcpy.MakeFeatureLayer statement. – Roland Apr 24 '13 at 15:44
  • Been looking a little more closely. The results are a little confusing. The AddJoin should have reduced the number of features (I used "KEEP_COMMON" in the AddJoin) in the layer. The actual map and table displays w/in ArcMap show the correct subset, but when I use arcpy.GetCount_management() on the layer, I get all of points in the original featureclass. This doesn't seem good because I'm wanting to iterate over the points w/in python. Am I checking the count of the wrong thing? – Roland Apr 24 '13 at 15:55

I seem to have a workaround based on the recommendation of a colleague.

I'm now using "KEEP_ALL" in the AddJoin() followed by a SelectLayerByAttribute_management() where the foreign key is null.

I now see and can programmatically confirm that the appropriate subset has been selected. Seems like I shouldn't have to make this extra step, but at least it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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