0

I'm trying to join up some data so I can make some rasters. I am doing this in Python but when I create the join in Python in results in an empty attribute table for my shapefile. The columns from both the shapefile and the view I am using in the join are in the shapefile after the join and my view shows up as a joined table in Joins and Relates but there are no data at all.

My Python is:

arcpy.AddJoin_management("Area1_wellspiezometers", "LocId_Calc", "_107062_1_1999", "LocationName")

Where

  • Area1_wellspiezometers is a shapefile
  • LocId_Calc is an field in Area1_wellspiezometers
  • _107062_1_1999 is a view created with arcpy.MakeTableView_management from a table in an MDB.
  • LocationName is a field in _107062_1_1999

Alternatively when I do this through the GUI I right click on Area1_wellspiezometers > Joins and Relates > Join... and enter my info as such:

enter image description here

This makes the join as expected and everything is dandy.

What is the difference between these two methods and how can I make the Python do what the GUI is doing?

  • Pretty sure the reason is you're trying to operate directly on the shapefile. If you read the first line of the help file you linked to, it states 'where layer is a feature layer'. And if you look at all the examples further down, note they all use arcpy.MakeFeatureLayer_management prior to the join function. – Chris W Dec 15 '14 at 21:21
  • @ChrisW If i make a FeatureLayer based on the shapefile first and join to that instead it is the same result. – Brad Dec 15 '14 at 22:41
1

I needed to save my Table View to disk in order for it to be usable by a join. CopyRows_management was the missing link.

arcpy.MakeTableView_management(outGdb + "\myTable", viewName, sqlFilterForView ,outGdb)
arcpy.CopyRows_management(viewName, saveViewPath)
arcpy.AddJoin_management( shapeLayer  , joinField,  savedViewName  , joinField,"KEEP_COMMON")

Other suggestions like making my view a spatial layer by using arcpy.MakeXYEventLayer_management were not successful.

0

not sure why it would work in the GUI - but according to the docs under 'Reasons joining tables may fail' - it does list "avoid starting field names with a number or an underscore" - and has similar warnings against the feature name as well.

  • If I rename my view V107062_1_1999 I get the same results – Brad Dec 15 '14 at 20:59
  • 1
    Shorter names of datasets help, especially with shapefiles – FelixIP Dec 15 '14 at 21:08
  • is the MDB that the table resides a GDB? or a standard MS MDB? – fluidmotion Dec 15 '14 at 21:10
  • @fluidmotion the mdb is a Personal GeoDatabase I created with ArcCatalog and pulled in a table from Excel (also from Catalog) using the import button on the context menu. – Brad Dec 15 '14 at 21:25
  • @FelixIP Do you know how short is short enough? – Brad Dec 18 '14 at 17:33

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.