0

The X Coordinates and Y Coordinates exist in the csv. However, I still get this error. Can anyone help?

ExecuteError: Failed to execute. Parameters are not valid. ERROR 000728: Field X Coordinates does not exist within table ERROR 000728: Field Y Coordinates does not exist within table Failed to execute (MakeXYEventLayer)

# Description: Creates an XY layer and exports it to a layer file

# import system modules 
import arcpy
import csv

arcpy.env.workspace = "C:/GEO345/Lab4/Lab4/"
 
# Set the local variables
in_Table = "C:\\GEO345\\Lab4\\Lab4\\Crimes_-_2010.csv"
out_Layer = "crime_2010_layer"
saved_Layer = r"c:\GEO345\Lab4\Lab4\crime_2010.lyr"

# Set the spatial reference
sr = arcpy.SpatialReference(4326)

# Make the XY event layer...
arcpy.MakeXYEventLayer_management(in_Table, 'X Coordinates', 'Y Coordinates', out_Layer, 
                                  sr)

# Save to a layer file
arcpy.SaveToLayerFile_management(out_Layer, saved_Layer)
3
  • 1
    probably a problem with the space in the field name, which could be confused with a field separator Try renaming your fields as Xcoordinates Ycoordinates
    – radouxju
    Commented Feb 23, 2021 at 10:24
  • Thanks a lot. That is what it was. Commented Feb 23, 2021 at 10:30
  • @radouxju I think you should write up a brief answer to this question.
    – PolyGeo
    Commented Feb 23, 2021 at 23:46

1 Answer 1

2

The field names contain spaces, which are non standard characters. Those special characters often cause problems, so you should either completely remove the space between X/Y and Coordinates, or replace it with "_" e.g. XCoordinates or X _Coordinates

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.