I made some adjustments to existing code, and now there seems to be a glitch down the line in an area where no adjustments were made.
My initial goal was to ensure the correct data types are shown in ArcGIS. Previously, I created an Excel spreadsheet (DatabaseJoin.xlsx) that sourced select information from another Excel spreadsheet. My Excel spreadsheet (DatabaseJoin.xlsx) contained formulas that pulled and displayed numbers, text, and dates taken from the original Excel spreadsheet.
Next, in ArcPy, I converted the Excel spreadsheet (DatabaseJoin.xlsx) to a dbf file (DatabaseJoin.dbf)to get rid of the formulas using ExceltoTable_conversion. I then joined the dbf file (DatabaseJoin.dbf) to a layer within my geodatabase (Projects.shp).
The problem with this original method was that everything was displayed as STRING, so I couldn't summarize the numbers in my mxd file.
My new method was to manually save a csv file (DatabaseJoin.csv) from the Excel spreadsheet (DatabaseJoin.xlsx) and make sure that all fields were saved as number, date, text, etc. In ArcPy, I joined the csv file (DatabaseJoin.csv) to my geodatabase layer (Projects.shp) and the field types carried over so I can now use the Statistics tool.
However... now I am getting issues when I alter the field names. I am receiving the following error message:
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000800: The value is not a member of TEXT | FLOAT | DOUBLE | SHORT | LONG | DATE | BLOB | RASTER | GUID.
Failed to execute (AlterField).
This error must be an issue with the csv file, right? I'm not sure if it has anything to do with it, but I notice when I open up the dbf file of the geodatabase layer in Excel, all of the field types show as 'NUMBER', even the text entries.
Here is my original code:
##### JOIN TO MAIN DATABASE
#Convert xlsx to table:
import xlrd
in_excel= r'C:\\VisualDatabase\\Planning_Out\\DatabaseJoin.xlsx'
out_table= r'C:\\VisualDatabase\\Planning_Out\\DatabaseJoin.gdb'
# Perform the conversion
join_table= arcpy.ExcelToTable_conversion(in_excel, out_table)
# Permanent Join
inFeatures= r'C:\\VisualDatabase\\Planning_Out\\Projects.shp'
layerName= "projects"
P_join=arcpy.MakeFeatureLayer_management(inFeatures, layerName)
# Set the local parameters
joinField= "Name"
joinField_P = "Contract"
outFeature = r'C:\\VisualDatabase\\Planning_Out\\P_join.shp'
joinTable= r'C:\\VisualDatabase\\Planning_Out\\DatabaseJoin.dbf'
# Join feature classes by joinField
arcpy.AddJoin_management ("projects", joinField, joinTable, joinField_P, "KEEP_COMMON")
arcpy.CopyFeatures_management("projects", outFeature)
#Contract
#Set local variables
Contractfield = "Database_1"
Contract_new_length = "20"
arcpy.AlterField_management(gdb,Contractfield, "CON", "CON", "TEXT", CON_new_length, "NULLABLE")
#Length
#Set local variables
Lengthfield = "Database_8"
Length_new_length = "200"
arcpy.AlterField_management(gdb,Lengthfield, "LENGTH", "Length", "TEXT", Length_new_length, "NULLABLE")
Here is my new code:
# Permanent Join
inFeatures= r'C:\\VisualDatabase\\Planning_Out\\Projects.shp'
layerName= "projects"
P_join=arcpy.MakeFeatureLayer_management(inFeatures, layerName)
# Set the local parameters
joinField= "Name"
joinField_P = "Contract"
outFeature = r'C:\\VisualDatabase\\Planning_Out\\P_join.shp'
joinTable= r'C:\\VisualDatabase\\Planning_Out\\DatabaseJoin.csv'
# Join feature classes by joinField
arcpy.AddJoin_management ("projects", joinField, joinTable, joinField_P, "KEEP_COMMON")
arcpy.CopyFeatures_management("projects", outFeature)
#Contract
#Set local variables
Contractfield = "Database_1"
Contract_new_length = "20"
arcpy.AlterField_management(gdb,Contractfield, "CON", "CON", CON_new_length, "NULLABLE")
#Length
#Set local variables
Lengthfield = "Database_8"
Length_new_length = "200"
arcpy.AlterField_management(gdb,Lengthfield, "LENGTH", "Length", Length_new_length, "NULLABLE")
Maybe field mapping can fix this and make it easier?