Hello
I am new to Python and I am trying to use the particle tracking with a CSV file of coordinates. So I want to run the particle tracking tool for several points listed in the file. I found an old post where someone made it work (Solved: Run Particle tracking tool for a set of points - Esri Community), and I tried to adapt the code to my project, but I keep running into one of these errors:
Parsing error SyntaxError: invalid syntax
Parsing error IndentationError: unexpected indent
I am not sure what the issue is, I tried to go over it several times, but I am not very experienced with python.
Any help is greatly appreciated!
-Louise
import arcpy
import os
from arcpy import env
from arcpy.sa import *
#set local variables
folder = r"C:\GIS\P8\Pythontest"
ws = r"C:\GIS\P8\Pythontest\python.gdb"
ds_name = "Tracklines"
inDirectionRaster = "curdir"
inMagnitudeRaster = "curmag"
stepLength = 10
trackingTime = 10000000
csv_file = r"C:\GIS\P8\Pythontest\pol_points_test.csv"
env.workspace = ws
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
i=0
try:
with open(csv_file ,'r') as infile:
for line in infile:
i += 1
if i != 1:
x = line.split(',')[1]
y = line.split(',')[2]
id = line.split(',')[0]
sourcePoint = arcpy.Point(float(x),float(y))
outTrackFile = os.path.join(folder, "xy_{0}.txt".format(id))
outTrackPolylineFeatures = os.path.join(ws, ds_name, "xy_{0}".format(id))
# Execute ParticleTrack
ParticleTrack(inDirectionRaster, inMagnitudeRaster, sourcePoint, outTrackFile, stepLength, trackingTime, outTrackPolylineFeatures)
arcpy.CheckInExtension("Spatial")
except:
print arcpy.GetMessages(2)