I'm trying to read multiple CSV files to my arcGIS pro project.
The csv files consist x,y coordinated so I would like to upload them to the project and show them on the map, as happends when I upload the CSV file through the 'MAP'-->'Add Data'-->'X,Y Point Data'.
I do this action very often so I would like to automate it.
I'll be happy to get some guidance or a script to do so.
Tnx a lot
There is sample code in the help, but it is for loading 1 file
XY Table To Point (Data Management)—ArcGIS Pro | Documentation
You can right-click on the tool in ArcToolbox and try it in batch mode
Then if you want a script, you can export to a script and modify it to suit your needs
When you do it manually, you open the tool XY Table To Point (Data Management)—ArcGIS Pro | Documentation.
To automate the process, you could use a script like this:
csv_files = [
"H:/test.csv",
# etc.
]
import os
wkid = 25832 # the wkid of your coordinate system
x = "X"
y = "Y"
z = None
gdb = None # path to the database where you want to save the feature class. None: default gdb of your project
for csv in csv_files:
print(csv)
name = os.path.basename(csv).split(".")[0]
if gdb is not None:
name = os.path.join(gdb, name)
arcpy.management.XYTableToPoint(csv, name, x, y, z, wkid)