I have two sets of shapefiles that I would like to join based on a similar field. They are all stored in a path folder which is stored as the variable "steps".
One group of shapefiles are polygon shapefiles named something like "polygonA_footprints.shp", "polygonB_footprints.shp" , "polygonC_footprints.shp"
The other group are a set of points shapefile named something like "polygonA_points.shp" "polygonB_points.shp", "polygonC_points.shp"
Both groups have the same field "PID".
I'd like to join the .dbf table from the points.shp layer to their matched polygon.shp.
The following is my code:
arcpy.env.workspace = steps
arcpy.env.overwriteOutput = True
shplist = arcpy.ListFiles("*footprints.shp")
tablelist = arcpy.ListFiles("*points.dbf")
for shp in shplist:
sprefix = shp.rsplit("*footprints.shp")[0]
for t in tablelist:
tprefix = t.rsplit("*points.dbf")[0]
if sprefix == tprefix:
arcpy.AddJoin_management(shp,"PID",t,"PID")
Running the code in PyCharm does not produce any error messages, however when I open the polygon.shp in ArcMap the join is not complete. I've tried using "*footprints.dbf" and "*footprints.shp" in Line 3 and experimented with my indentations of the 'for' lines to no avail.
Can someone tell me what's wrong with my code? I have also tried:
arcpy.env.workspace = steps
arcpy.env.overwriteOutput = True
shplist = arcpy.ListFiles("*footprints.shp")
tablelist = arcpy.ListFiles("*geotagswBearings.dbf")
for shp in shplist:
sprefix = shp.rsplit("*footprints.shp")[0]
for t in tablelist:
tprefix = t.rsplit("*geotagswBearings.dbf")[0]
if sprefix == tprefix:
arcpy.AddJoin_management(shp,"PID",t,"PID")
and:
arcpy.env.workspace = steps
arcpy.env.overwriteOutput = True
shplist = arcpy.ListFiles("*footprints.shp")
tablelist = arcpy.ListFiles("*geotagswBearings.dbf")
for shp in shplist:
for t in tablelist:
sprefix = shp.rsplit("*footprints.shp")[0]
tprefix = t.rsplit("*geotagswBearings.dbf")[0]
if sprefix == tprefix:
arcpy.AddJoin_management(shp,"PID",t,"PID")
and I've also tried substituting "*footprints.dbf" for "*footprints.shp" as I thought it might need the input_layer table instead of feature class based on the Desktop help section (https://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/add-join.htm)