<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using Python for particle tracking with a set of points in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-python-for-particle-tracking-with-a-set-of/m-p/1279585#M67439</link>
    <description>&lt;P&gt;I am using the python window in ArcMap, I am not sure when I should execute it or stop with the ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Apr 2023 09:55:47 GMT</pubDate>
    <dc:creator>LouiseTaylor</dc:creator>
    <dc:date>2023-04-18T09:55:47Z</dc:date>
    <item>
      <title>Using Python for particle tracking with a set of points</title>
      <link>https://community.esri.com/t5/python-questions/using-python-for-particle-tracking-with-a-set-of/m-p/1279575#M67437</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;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 (&lt;A href="https://community.esri.com/t5/python-questions/run-particle-tracking-tool-for-a-set-of-points/td-p/696829" target="_blank"&gt;Solved: Run Particle tracking tool for a set of points - Esri Community&lt;/A&gt;),&amp;nbsp; and I tried to adapt the code to my project, but I keep running into one of these errors:&lt;/P&gt;&lt;P&gt;Parsing error SyntaxError: invalid syntax&lt;/P&gt;&lt;P&gt;Parsing error IndentationError: unexpected indent&lt;/P&gt;&lt;P&gt;I am not sure what the issue is, I tried to go over it several times, but I am not very experienced with python.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Louise&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;from arcpy import env&lt;/P&gt;&lt;P&gt;from arcpy.sa import *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#set local variables&lt;/P&gt;&lt;P&gt;folder = r"C:\GIS\P8\Pythontest"&lt;/P&gt;&lt;P&gt;ws = r"C:\GIS\P8\Pythontest\python.gdb"&lt;/P&gt;&lt;P&gt;ds_name = "Tracklines"&lt;/P&gt;&lt;P&gt;inDirectionRaster = "curdir"&lt;/P&gt;&lt;P&gt;inMagnitudeRaster = "curmag"&lt;/P&gt;&lt;P&gt;stepLength = 10&lt;/P&gt;&lt;P&gt;trackingTime = 10000000&lt;/P&gt;&lt;P&gt;csv_file = r"C:\GIS\P8\Pythontest\pol_points_test.csv"&lt;/P&gt;&lt;P&gt;env.workspace = ws&lt;/P&gt;&lt;P&gt;# Check out the ArcGIS Spatial Analyst extension license&lt;/P&gt;&lt;P&gt;arcpy.CheckOutExtension("Spatial")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i=0&lt;/P&gt;&lt;P&gt;try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; with open(csv_file ,'r') as infile:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for line in infile:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i != 1:&lt;/P&gt;&lt;P&gt;x = line.split(',')[1]&lt;/P&gt;&lt;P&gt;y = line.split(',')[2]&lt;/P&gt;&lt;P&gt;id = line.split(',')[0]&lt;/P&gt;&lt;P&gt;sourcePoint = arcpy.Point(float(x),float(y))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;outTrackFile = os.path.join(folder, "xy_{0}.txt".format(id))&lt;/P&gt;&lt;P&gt;outTrackPolylineFeatures = os.path.join(ws, ds_name, "xy_{0}".format(id))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Execute ParticleTrack&lt;/P&gt;&lt;P&gt;ParticleTrack(inDirectionRaster, inMagnitudeRaster, sourcePoint, outTrackFile, stepLength, trackingTime, outTrackPolylineFeatures)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CheckInExtension("Spatial")&lt;/P&gt;&lt;P&gt;except:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages(2)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 09:27:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-for-particle-tracking-with-a-set-of/m-p/1279575#M67437</guid>
      <dc:creator>LouiseTaylor</dc:creator>
      <dc:date>2023-04-18T09:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python for particle tracking with a set of points</title>
      <link>https://community.esri.com/t5/python-questions/using-python-for-particle-tracking-with-a-set-of/m-p/1279578#M67438</link>
      <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It is hard to read your code to check for improper indentation.&lt;/P&gt;&lt;P&gt;Any good python IDE should point out indentation and other errors, so check your .... try .... except block first and format your code for posting here so that there are line numbers to refer to&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 09:34:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-for-particle-tracking-with-a-set-of/m-p/1279578#M67438</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-04-18T09:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python for particle tracking with a set of points</title>
      <link>https://community.esri.com/t5/python-questions/using-python-for-particle-tracking-with-a-set-of/m-p/1279585#M67439</link>
      <description>&lt;P&gt;I am using the python window in ArcMap, I am not sure when I should execute it or stop with the ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 09:55:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-for-particle-tracking-with-a-set-of/m-p/1279585#M67439</guid>
      <dc:creator>LouiseTaylor</dc:creator>
      <dc:date>2023-04-18T09:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python for particle tracking with a set of points</title>
      <link>https://community.esri.com/t5/python-questions/using-python-for-particle-tracking-with-a-set-of/m-p/1279587#M67440</link>
      <description>&lt;P&gt;Sorry, I just saw the link you added with the code formatting, I have tried to show it here:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy
&amp;gt;&amp;gt;&amp;gt; import os
&amp;gt;&amp;gt;&amp;gt; from arcpy import env
&amp;gt;&amp;gt;&amp;gt; from arcpy.sa import *
&amp;gt;&amp;gt;&amp;gt; #set local variables
&amp;gt;&amp;gt;&amp;gt; folder = r"C:\GIS\P8\Pythontest"
&amp;gt;&amp;gt;&amp;gt; ws = r"C:\GIS\P8\Pythontest\python.gdb"
&amp;gt;&amp;gt;&amp;gt; ds_name = "Tracklines"
&amp;gt;&amp;gt;&amp;gt; inDirectionRaster = "curdir"
&amp;gt;&amp;gt;&amp;gt; inMagnitudeRaster = "curmag"
&amp;gt;&amp;gt;&amp;gt; stepLength = 10
&amp;gt;&amp;gt;&amp;gt; trackingTime = 10000000
&amp;gt;&amp;gt;&amp;gt; csv_file = r"C:\GIS\P8\Pythontest\pol_points_test.csv"
&amp;gt;&amp;gt;&amp;gt; env.workspace = ws
&amp;gt;&amp;gt;&amp;gt; # Check out the ArcGIS Spatial Analyst extension license
&amp;gt;&amp;gt;&amp;gt; arcpy.CheckOutExtension("Spatial")
u'CheckedOut'
&amp;gt;&amp;gt;&amp;gt; i=0
&amp;gt;&amp;gt;&amp;gt; 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))
...                  
Parsing error SyntaxError: invalid syntax (line 10)

&amp;gt;&amp;gt;&amp;gt; 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)
...                      
Parsing error SyntaxError: invalid syntax (line 15)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 09:53:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-for-particle-tracking-with-a-set-of/m-p/1279587#M67440</guid>
      <dc:creator>LouiseTaylor</dc:creator>
      <dc:date>2023-04-18T09:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python for particle tracking with a set of points</title>
      <link>https://community.esri.com/t5/python-questions/using-python-for-particle-tracking-with-a-set-of/m-p/1279617#M67442</link>
      <description>&lt;P&gt;It is your try-except block, it isn't indented properly,&lt;/P&gt;&lt;LI-CODE lang="python"&gt;try:
    with.... and the rest
except:
    print(...&lt;/LI-CODE&gt;&lt;P&gt;you need to use a python IDE aka, editor not the python window&amp;nbsp; to load and create python scripts&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 12:26:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-for-particle-tracking-with-a-set-of/m-p/1279617#M67442</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-04-18T12:26:46Z</dc:date>
    </item>
  </channel>
</rss>

