I am trying to create xy event layers that display data from csv tables as points, I would like to loop the normal make x y event layer through the directory that my files are stored in. This data has no georeference and that is accounted for within the code.
I have created a function that lists out the files that in the directory I need. Then through a series of functions I can create a series of output filenames that correspond with the names of the input files that I have put into the function.
I keep getting an error message:
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.6\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec codeObject in __main__.__dict__
File "D:\Documents\functions.py", line 47, in <module>
loop_event_layer(csv_list, layer_file)
File "D:\Documents\functions.py", line 44, in loop_event_layer
arcpy.MakeXYEventLayer_management(table = i, in_x_field = "X", in_y_field = "Y", out_layer = x, spatial_reference="{B286C06B-0879-11D2-AACA-00C04FA33C20};IsHighPrecision", in_z_field = "PI")
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\management.py", line 7618, in MakeXYEventLayer
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: XY Table: Dataset 0 does not exist or is not supported
Failed to execute (MakeXYEventLayer).
The code is below:
import arcpy
import os
#and separates the name at the .csv to give the beginning of the name. The outputs of this new name list have new
#extensions added such as point and raster.
arcpy.env.workspace = "D:/Documents/PhD/GIS/Odhran.gdb/"
path = "C:/Users/MarPAMM/Desktop/Test_with_Ger_for_csv_raster_conversion/"
output = "D:/Documents/PhD/GIS/Odhran.gdb/"
entries = os.listdir(path)
extension = "result.csv"
def list_csv(x):
csv_list = []
for i in x:
if i.endswith(extension):
csv_list.append(i)
return csv_list
csv_list = list_csv(entries)
def split_csv_name(x):
filename = []
start = []
for i in x:
start, end = i.split(".")
filename.append(start)
return filename
output_file_beginning = split_csv_name(csv_list)
layer_extension = "_layer"
point_extension = "_point"
raster_extension = "_raster"
def join_name(x, extension):
filename = []
for i in x:
filename.append(i + extension)
return filename
layer_file = join_name(output_file_beginning, layer_extension)
def loop_event_layer(input_file, output_file):
for i,x in zip(range(len(input_file)),range(len(output_file))):
arcpy.MakeXYEventLayer_management(table = i, in_x_field = "X", in_y_field = "Y", out_layer = x, spatial_reference="{B286C06B-0879-11D2-AACA-00C04FA33C20};IsHighPrecision", in_z_field = "PI")
return x
loop_event_layer(csv_list, layer_file)