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.

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
u'01170000'
>>> arcpy.GetCount_management("StreamGageEvent")
<Result '1'>
>>> for row in arcpy.SearchCursor("StreamGageEvent"):
...     sourcefea=row.getValue("SOURCE_FEA")
...     
>>> sourcefea
u'01170000'
>>> if gageid==sourcefea:
...     print 'yes'
...     
yes
>>> 
>>> arcpy.AddJoin_management("GagesII", 'GAGE_ID', "StreamGageEvent", "SOURCE_FEA", "KEEP_COMMON")
<Result 'GagesII'>
>>> 
>>> arcpy.GetCount_management("GagesII")
<Result '-1'>
share|improve this question

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

2 Answers 2

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.

share|improve this answer
    
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
up vote 1 down vote accepted

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.

share|improve this answer
    
This is a known 10.0 problem. support.esri.com/en/bugs/nimbus/TklNMDc2NDk2 Fix is in 10.1. Big argument to get to 10.1 asap. –  Roland Apr 30 '13 at 21:41

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.