Arc Pro Field Mapping not working in Export Table conversion tool

3078
12
Jump to solution
02-14-2024 08:36 AM
FranklinAlexander
Frequent Contributor

I have done this hundreds of times, but something seems to have changed in the last Arc Pro update. I have a Python script where I am trying to convert a spreadsheet into a point layer.  Below is what I tried first, but the latitude and longitude fields will not convert to Double. 

# Process: Excel To Table (Excel To Table) (conversion)
arcpy.AddMessage("Converting spreadsheet to DB Table")
logging.info("Converting spreadsheet to DB Table")
excelToTable = os.path.join(TempWS, "excelToTable")
arcpy.AddMessage("Excel to table path " + excelToTable)
arcpy.conversion.ExcelToTable(Input_Excel_File=spreadsheet, Output_Table=excelToTable, Sheet="Debris Harvest Data Florida")
fm = ("list_name \"List Name\" true true false 100 Text 0 0,First,#,excelToTable,list_name,0,254;" +
          "item_id \"Item ID\" true true false 10 Text 0 0,First,#,excelToTable,item_id,0,254;" +
          "itemname \"Item Name\" true true false 255 Text 0 0,First,#,excelToTable,itemname,0,254;" +
          "material \"Material\" true true false 255 Text 0 0,First,#,excelToTable,material,0,254;" +
          "quantity \"Quantity\" true true false 255 Text 0 0,First,#,excelToTable,quantity,0,254;" +
          "description \"Description\" true true false 255 Text 0 0,First,#,excelToTable,description,0,254;" +
          "latitude \"Latitude\" true true false 8 Double 0 0,First,#,excelToTable,latitude,0,254;" +
          "longitude \"Longitude\" true true false 8 Double 0 0,First,#,excelToTable,longitude,0,254;" +
          "altitude \"Altitude\" true true false 255 Float 0 0,First,#,excelToTable,altitude,0,254;" +
          "radius \"Radius\" true true false 255 Float 0 0,First,#,excelToTable,radius,0,254;" +
          "location \"Location\" true true false 255 Text 0 0,First,#,excelToTable,location,0,254;" +
          "timestamp \"Timestamp\" true true false 255 Text 0 0,First,#,excelToTable,timestamp,0,254;" +
          "dt \"Datetime\" true true false 255 Date 0 0,First,#,excelToTable,dt,0,254;" +
          "project_name \"Project Name\" true true false 255 Text 0 0,First,#,excelToTable,project_name,0,254;" +
          "project_id \"Project ID\" true true false 255 Long 0 0,First,#,excelToTable,project_id,0,254;" +
          "username \"Username\" true true false 255 Text 0 0,First,#,excelToTable,username,0,254;" +
          "user_index \"User Index\" true true false 255 Long 0 0,First,#,excelToTable,user_index,0,254;" +
          "manual_upload \"Manual Upload\" true true false 255 Text 0 0,First,#,excelToTable,manual_upload,0,254;" +
          "event_name \"Event Name\" true true false 255 Text 0 0,First,#,excelToTable,event_name,0,254;" +
          "id \"ID\" true true false 255 Text 0 0,First,#,excelToTable,id,0,254;" +
          "log_index \"Log Index\" true true false 255 Long 0 0,First,#,excelToTable,log_index,0,254")

# Process: Export Table (Export Table) (conversion)
    arcpy.AddMessage("Exporting table and mapping fields")
    logging.info("Exporting table and mapping fields")
    MDD_exportTable = os.path.join(TempWS, "MDD_exportTable")
    arcpy.conversion.ExportTable(in_table=excelToTable, out_table=MDD_exportTable, field_mapping=fieldMap)

# Process: XY Table To Point (XY Table To Point) (management)
    arcpy.AddMessage("Displaying XY values and creating point feature class")
    logging.info("Displaying XY values and creating point feature class")
    MDD_tableToPoint = os.path.join(TempWS, "MDD_tableToPoint")
    arcpy.management.XYTableToPoint(in_table=MDD_exportTable, out_feature_class=MDD_tableToPoint, x_field="lon", y_field="lat", 
                                    coordinate_system="GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]];-400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119521E-09;0.001;0.001;IsHighPrecision")

 

In the exported table, the latitude and longitude fields are still Text fields and I cannot display XY values using these fields. I also tried adding new fields in the field map and then calculating them, but iy seems as though the Table Export tool is ignoring the field mapping altogether because there are no new fields created to run the Calculate Field tool on. I noticed that in the last ArcPro update, the field mapping tool interface has changed, so I am wandering if something got messed up in the last update. I really don't want to have to write an extra 100 lines of code to do this, so if anyone has any insight please share. 🙂

Tags (2)
12 Replies
DavidTillberg_community
Occasional Contributor

I had issue after upgrade to pro 3.2 with Append tool in Python scripts where I build a field mappings object and was passing that as parameter in the append line like this.  This code worked fine previously:
(Note:  fldMappings is the FieldMappings object, I am using full paths to all feature classes which are in different workspaces, and not changing workspace on arcpy.env object at all)

arcpy.management.Append(inputs,target,'NO_TEST',fldMappings)

It turned out that calling python str function on the fldMappings object made it work again!  Now my code looks like this and it works:

arcpy.management.Append(inputs,target,'NO_TEST',str(fldMappings))
NickN
by
Frequent Contributor

I also ran into fieldMapping failing in Python with the Append tool after upgrading Pro from 3.0.3 to 3.1.5. I even tested in 3.2, same issue. The fieldmap would only work on fields that had the same name in the source and destination. Wrapping the fieldmap in str() as David mentioned fixed the issue.

mmetzcar
Occasional Contributor

Related to this, but slightly different, in the UI for the Export Features geoprocessing tool, the Field Map would reset itself before I could run the tool effectively rendering the Field Map useless. The solution to this post pointed me to the workaround. So long as the feature I'm trying to export is in my default geodatabase, then the Export Features tool's UI works as expected. 🎉