Field Mapping Help With Merge Tool

Discussion created by Lady_Jane on Mar 21, 2011
Latest reply on Dec 20, 2012 by AdamCox
I'm new to python and using fieldmappings for the first time.
I have a script that creates two dBASE tables.  I would like one of the final steps in my script to be merging these two tables and keeping only two fields (UCID and Temp).  In the table "statTableV" these fields are "UCID" and "MEAN".  In the table "pointValuesV" these fields are "CATCH_02_3" and "RASTERVALU".  So I need to rename the fields and merge them.

I wrote the code below based on the code example provided here:
but that is resulting in this error: ExecuteError: ERROR 000468: Input shape types are not equal
Failed to execute (Merge).
Which brings me to my question:
a) What is causing the error?
b) Most of the fields in my input tables are ones I don't need.  Do I have to specify that they be removed in field mapping or with they be ignored if they are not specified in the code?


# Import Modules
import arcgisscripting

# Create geoprocessor object
gp = arcgisscripting.create (9.3)

# Get parameters
catchments = r"F:\Climate\test\Catchments.gdb\Catch_02AA"
#catchments = gp.GetParameterAsText(0)                                  # Feature Layer
watershed = "02AA"
#watershed = gp.GetParameterAsText(1)
idField = "UCID"
#idField = gp.GetParameterAsText(2)                                     # Field
climateRaster = r"F:\Climate\test\Climate.gdb\Avg_Temp_January"
#climateRaster = gp.GetParameterAsText(3)                               # Raster Layer
month = "January"
#month = gp.GetParameterAsText (4)                                      # String
workspace = r"F:\Climate\test\Climate.gdb"
#workspace = gp.GetParameterAsText (5)                                  # Workspace
outWorkspace = r"F:\Climate\test"
#outWorkspace = gp.GetParameterAsText (6)                               # Folder

statTable = "zStat" + month
statTableV = "zStat" + month + "V"
missingStats = "zStat" + month + "Missing"
points = month + "Point"
pointValues = month + "PointValue"
pointValuesV = month + "PointValuesV"
finalTable = month + "Averages" + watershed
gp.Workspace = workspace
gp.overwriteoutput = True

# Check-out the Spatial Analyst extension
gp.CheckOutExtension ("Spatial")

# Run Zonal Statistics As Table
gp.ZonalStatisticsAsTable_sa (catchments, idField, climateRaster, statTable, "DATA")

# Create a feature layer from the catchments
gp.MakeFeatureLayer_management (catchments, "layer", "", workspace, "")

# Join zonal statistics table to catchments layer
gp.AddJoin_management ("layer", idField, statTable, idField, "KEEP_ALL")

# Select and export the catchments that don't have any zonal statistics
gp.Select_analysis ("layer", missingStats, '"' + statTable + "." + idField + '"' + ' is null')

# Un-join zonal statistics table from catchments
gp.RemoveJoin_management ("layer", statTable)

# Convert the exported "missing stats" catchments to point centroids
gp.FeatureToPoint_management (missingStats, points, "INSIDE")

# Add the underlying temperature values to the points
gp.ExtractValuesToPoints_sa (points, climateRaster, pointValues, "INTERPOLATE", "VALUE_ONLY")

# Make table views from the zonal statistics and value to points tables
gp.MakeTableView_management (statTable, statTableV, "", workspace, idField + " " + idField + " VISIBLE, RASTERVALU Temp VISIBLE")
gp.MakeTableView_management (pointValues, pointValuesV, "", workspace, idField + " " + idField + " VISIBLE, MEAN Temp VISIBLE")

# Convert table views to dBASE tables
gp.TableToDBASE_conversion (statTableV, outWorkspace)
gp.TableToDBASE_conversion (pointValuesV, outWorkspace)

# Prepare the field maps for the final table
fieldMappings = gp.createobject ("FieldMappings")
fldmap_UCID = gp.createobject ("FieldMap")
fldmap_Temp = gp.createobject ("FieldMap")
vt = gp.CreateObject("ValueTable")
fldmap_UCID.AddInputField(statTableV, "UCID")
fldmap_UCID.AddInputField(pointValuesV, "CATCH_02_3")
fldmap_Temp.AddInputField(statTableV, "MEAN")
fldmap_Temp.AddInputField(pointValuesV, "RASTERVALU")
fld_UCID = fldmap_UCID.OutputField
fld_Temp = fldmap_Temp.OutputField
fld_UCID.Name = "UCID"
fld_Temp.Name = "Temp"
fldmap_UCID.OutputField = fld_UCID
fldmap_Temp.OutputField = fld_Temp

# Merge the two tables
gp.Merge_management (vt, finalTable, fieldMappings)

# Delete all the temporary datasets
gp.Delete_management (statTable)
gp.Delete_management (missingStats)
gp.Delete_management (points)
gp.Delete_management (pointValues)
gp.Delete_management (statTableV + ".dbf")
gp.Delete_management (pointValuesV + ".dbf")