Select to view content in your preferred language

AddJoin Issue

710
4
08-05-2022 08:44 PM
JDScharf
Occasional Contributor

Hi everyone,
I am learning Python development to help automate some of my regular data processes and am running into an issue.

I have table layer that will be regularly updated with new data, which I then am joining to a Parcel Geodatabase by a shared identifier.

I can do this in ArcGIS Pro by doing an AddJoin.  When I have looked at the ESRI documentation to use manager.AddJoin for this, it seems to make sense, but I cannot get the scripting to work.

Here is the code that I am working on so far:

 

 

from arcgis.gis import GIS
from arcgis import features
from arcgis.features import FeatureLayer
import arcpy
import pandas as pd
import geopandas
import os

# Assigns ID for Feature Layer
rental_feature_ID = "c2af294c42284b89b1fbe9d633302161"
rental_feature_item = gis.content.get(rental_feature_ID)
rental_feature_item
rental_feature_item.tables[0]
table_url = "https://services6.arcgis.com/bdPqSfflsdgFRVVM/arcgis/rest/services/Rental Registry Auto-Update No Geocode/FeatureServer/0"

# I don't really understand this part, but it seems to allow you to reference properties from the parcel_layer
rental_table_layer = FeatureLayer(table_url)
rental_table_layer

# Assign ID for the most recent Parcel Map in the Portal
parcel_layer_ID = "e16339e911064240ad670b9f83ba0163"

# Assigns the Parcel Feature Layer to a variable
parcel_feature_layer = gis.content.get(parcel_layer_ID)
parcel_feature_layer
parcel_feature_layer.layers
layer_url = "https://services6.arcgis.com/bdPqSfflsdgFRVVM/arcgis/rest/services/Parcel_Map_Q1_2020/FeatureServer/0"

# I don't really understand this part, but it seems to allow you to reference properties from the parcel_layer
parcel_layer = FeatureLayer(layer_url)
parcel_layer

# Set local variables
inFeatures = parcel_layer
joinTable = rental_table_layer
joinField = "SBL"

#Trying to use ArcPy ValidateJoin
validate_join = arcpy.management.ValidateJoin(inFeatures, joinField, joinTable, joinField)

# Trying to use ArcPy Join
rental_joined_table = arcpy.AddJoin_management(inFeatures, joinField, joinTable, joinField)
rental_joined_table

 

 

The errors that I am getting are:

-Ffor the ValidateJoin function:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-17-dbab836410c9> in <module>
----> 1 validate_join = arcpy.management.ValidateJoin(inFeatures, joinField, joinTable, joinField)

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in ValidateJoin(in_layer_or_view, in_field, join_table, join_field, output_msg)
   8654         return retval
   8655     except Exception as e:
-> 8656         raise e
   8657 
   8658 

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in ValidateJoin(in_layer_or_view, in_field, join_table, join_field, output_msg)
   8651     from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
   8652     try:
-> 8653         retval = convertArcObjectToPythonObject(gp.ValidateJoin_management(*gp_fixargs((in_layer_or_view, in_field, join_table, join_field, output_msg), True)))
   8654         return retval
   8655     except Exception as e:

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in <lambda>(*args)
    510         val = getattr(self._gp, attr)
    511         if callable(val):
--> 512             return lambda *args: val(*gp_fixargs(args, True))
    513         else:
    514             return convertArcObjectToPythonObject(val)

RuntimeError: Object: Error in executing tool

 

- Error's I'm getting for the AddJoin Function:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-82-2745ba596294> in <module>
----> 1 rental_joined_table = arcpy.management.JoinField(inFeatures, joinField, joinTable, joinField, {joinField})
      2 rental_joined_table

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in JoinField(in_data, in_field, join_table, join_field, fields)
   8582         return retval
   8583     except Exception as e:
-> 8584         raise e
   8585 
   8586 @gptooldoc('RemoveJoin_management', None)

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in JoinField(in_data, in_field, join_table, join_field, fields)
   8579     from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
   8580     try:
-> 8581         retval = convertArcObjectToPythonObject(gp.JoinField_management(*gp_fixargs((in_data, in_field, join_table, join_field, fields), True)))
   8582         return retval
   8583     except Exception as e:

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in <lambda>(*args)
    510         val = getattr(self._gp, attr)
    511         if callable(val):
--> 512             return lambda *args: val(*gp_fixargs(args, True))
    513         else:
    514             return convertArcObjectToPythonObject(val)

RuntimeError: Object: Error in executing tool

 

Tags (3)
0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

what are some of the outputs?  for instance is the input feature layer correctly identified? Did validate join return any messages etc


... sort of retired...
0 Kudos
JDScharf
Occasional Contributor

Hi Dan,
Thanks so much for the response.  I added the error message that I'm getting on the validatejoin function to my original post above.  I also worked on trying to make sure I'm identifying the correct layer for the functions.  I don't really no what to do wiht the "Object: Error in executing tool" error that I'm getting and really appreciate your time!

~Jason

0 Kudos
by Anonymous User
Not applicable

Since you are using the ArcGIS for Python API and hosted layers, you should use the join_features method from the api because the parcel_layer object that is created from FeatureLayer() is a Feature Layer, Feature Layer Collection, or Feature Collection, not a Table View as AddJoin requires.

join_features 

Give that a try-

AddJoin does mention feature layer as an input, but doesn't clarify if its referring to the Feature Layer object, or the blanket term for 'similar geographic features, for example, buildings, parcels, cities, roads, and earthquake epicenters.'

0 Kudos
JDScharf
Occasional Contributor

Thanks so much JeffK!
I will give this a try when I have a moment, and will let you know how this works!  Thank you 🙂

~Jason 

0 Kudos