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.management.AddField(inFeatures, newField, "TEXT")
# Create a feature layer from the vegtype featureclass
arcpy.management.MakeFeatureLayer(inFeatures, layerName)
# Join the feature layer to a table
arcpy.management.AddJoin(layerName, joinField, joinTable, joinField)
# Populate the newly created field with values from the joined table
arcpy.management.CalculateField(layerName, newField, calcExpression, "PYTHON")
# Remove the join
arcpy.management.RemoveJoin(layerName, "vegtable")
# Copy the layer to a new permanent feature class
arcpy.management.CopyFeatures(layerName, outFeature)