AnsweredAssumed Answered

Error with XY Table to Point in Python Script

Question asked by kclark_SubTelForum on Mar 6, 2020
Latest reply on Apr 2, 2020 by Dan_Patterson

I am receiving the following error when trying to use XY Table to Point in a Python Script:

 

Traceback (most recent call last):
  File "C:\Users\kierc\projects\SubTelCableMap\01 Update Current Position.py", line 22, in <module>
    arcpy.XYTableToPoint_management(in_table=Ship_Positions_csv, out_feature_class=ShipLatestPosition, x_field="AIS.LONGITUDE", y_field="AIS.LATITUDE", z_field="", 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")
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 3992, in XYTableToPoint
    raise e
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 3989, in XYTableToPoint
    retval = convertArcObjectToPythonObject(gp.XYTableToPoint_management(*gp_fixargs((in_table, out_feature_class, x_field, y_field, z_field, coordinate_system), True)))
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 511, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Traceback (most recent call last):
  File "c:\program files\arcgis\pro\Resources\ArcToolbox\Scripts\XYTableToPoint.py", line 183, in <module>
    xy_table_to_points(in_table, output_fc, x_field, y_field, z_field, coordinate_system)
  File "c:\program files\arcgis\pro\Resources\ArcToolbox\Scripts\XYTableToPoint.py", line 158, in xy_table_to_points
    coord_values.append(row[scur.fields.index(val)])
ValueError: tuple.index(x): x not in tuple

Failed to execute (XYTableToPoint).

 

Unfortunately, I'm having trouble understanding just what this error means. This script previously ran without trouble on a previous computer. I have kept all filenames and file paths the same. Even running a normal XY Table to Point tool within ArcGIS Pro fails to complete with the following error:

 

 Traceback (most recent call last):
  File "c:\program files\arcgis\pro\Resources\ArcToolbox\Scripts\XYTableToPoint.py", line 183, in <module>
    xy_table_to_points(in_table, output_fc, x_field, y_field, z_field, coordinate_system)
  File "c:\program files\arcgis\pro\Resources\ArcToolbox\Scripts\XYTableToPoint.py", line 158, in xy_table_to_points
    coord_values.append(row[scur.fields.index(val)])
ValueError: tuple.index(x): x not in tuple
Failed to execute (XYTableToPoint).

 

Looking for any guidance here. The code for the Python script is as follows:

 

# -*- coding: utf-8 -*-
"""Generated by ArcGIS ModelBuilder on: 2019-12-14 00:22:34
All ModelBuilder functionality may not be exported. Edits may be required for equivalency with the original model.
"""


import arcpy

# To allow overwriting the outputs change the overwrite option to true.
arcpy.env.overwriteOutput = True

# Local variables:
Ship_Positions_csv = r"C:\Users\kierc\projects\api\Ship_Positions.csv"
ShipLatestPosition = r"C:\Users\kierc\Documents\ArcGIS\Projects\SubTelCableMap\SubTelCableMap.gdb\ShipLatestPosition"
CurrentCableShipPositionTmp = r"C:\Users\kierc\Documents\ArcGIS\Projects\SubTelCableMap\SubTelCableMap.gdb\CurrentCableShipPositionTmp"
Updated_Target_Dataset = CurrentCableShipPositionTmp
CurrentCableShipPosition = r"C:\Users\kierc\Documents\ArcGIS\Projects\SubTelCableMap\SubTelCableMap.gdb\CurrentCableShipPosition"
Updated_Input_With_Rows_Removed = CurrentCableShipPosition

# Process: XY Table To Point
tempEnvironment0 = arcpy.env.outputCoordinateSystem
tempEnvironment0 = arcpy.env.outputCoordinateSystem
arcpy.XYTableToPoint_management(in_table=Ship_Positions_csv, out_feature_class=ShipLatestPosition, x_field="AIS.LONGITUDE", y_field="AIS.LATITUDE", z_field="", 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")
arcpy.env.outputCoordinateSystem = tempEnvironment0

# Process: Copy Features
arcpy.CopyFeatures_management(in_features=ShipLatestPosition, out_feature_class=CurrentCableShipPositionTmp, config_keyword="", spatial_grid_1="", spatial_grid_2="", spatial_grid_3="")

# Process: Delete Rows
arcpy.DeleteRows_management(in_rows=CurrentCableShipPosition)

# Process: Append
arcpy.Append_management(inputs=r"C:\Users\kierc\Documents\ArcGIS\Projects\SubTelCableMap\SubTelCableMap.gdb\CurrentCableShipPositionTmp", target=Updated_Input_With_Rows_Removed, schema_type="TEST", field_mapping="", subtype="", expression="")



 

This was originally made with Model Builder in Pro 2.4 and cleaned up/tweaked slightly by me after exporting to a editable Python file.

 

Edit:

For some reason, manually renaming the AIS.LATITUDE/AIS.LONGITUDE fields in my CSV file to simply LATITUDE/LONGITUDE allows the XY Table to Point tool to run successfully in ArcGIS Pro. I'm not sure why this would suddenly not work and I'd rather not having to add an additional step of renaming data fields.

Outcomes