Mit diesem eigenständigen Skript wird gezeigt, wie die Funktion RemoveJoin als Teil eines Workflow verwendet wird, mit dem einer Tabelle ein Feld hinzugefügt wird und die zugehörigen Werte anhand der Werte aus einer verbundenen Tabelle berechnet werden.
# AddFieldFromJoin.py
# Description: Adds a field to a table, and calculates its values based
# on the values in a field from a joined table
# Import system modules
import arcpy
# set the environments
arcpy.env.workspace = "C:/data"
arcpy.env.qualifiedFieldNames = "UNQUALIFIED"
# Define script parameters
inFeatures = "Habitat_Analysis.gdb/vegtype"
layerName = "veg_layer"
newField = "description"
joinTable = "vegtable.dbf"
joinField = "HOLLAND95"
calcExpression = "!vegtable.VEG_TYPE!"
outFeature = "Habitat_Analysis.gdb/vegjoin335"
# Add the new field
arcpy.AddField_management (inFeatures, newField, "TEXT")
# Create a feature layer from the vegtype featureclass
arcpy.MakeFeatureLayer_management (inFeatures, layerName)
# Join the feature layer to a table
arcpy.AddJoin_management (layerName, joinField, joinTable, joinField)
# Populate the newly created field with values from the joined table
arcpy.CalculateField_management (layerName, newField, calcExpression, "PYTHON")
# Remove the join
arcpy.RemoveJoin_management (layerName, "vegtable")
# Copy the layer to a new permanent feature class
arcpy.CopyFeatures_management (layerName, outFeature)