<?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 Using Hec-GeoHMS Longest Flowpath Tool within For loop in Water Resources Questions</title>
    <link>https://community.esri.com/t5/water-resources-questions/using-hec-geohms-longest-flowpath-tool-within-for/m-p/309247#M1467</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a feature class made of hundreds of polygons, that I need to determine the longest flow path for using HEC-GeoHMS. As anyone who has used this tool knows, you can't just pass the toolset the entire feature class if any of the watersheds overlap - it will not correctly calculate the longest flowpath for overlapping basins.&lt;/P&gt;&lt;P&gt;So, I am trying to setup a script that iterates through each record in my feature class and generates a longest flow path result for each record separately.&lt;/P&gt;&lt;P&gt;Here is my script so far:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# import stuff&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
 
 &lt;SPAN class="comment token"&gt;# import HEC-GeoHMS toolbox&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ImportToolbox&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcToolbox\Toolboxes\GeoHMS Tools.tbx"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# set environments&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;extent &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"MAXOF"&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;overwriteOutput &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"TRUE"&lt;/SPAN&gt;
 
 DEM &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; DEM &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; '&lt;SPAN class="comment token"&gt;#' or not DEM:&lt;/SPAN&gt;
 DEM &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"agreedem"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# provide a default value if unspecified&lt;/SPAN&gt;
 
 Flow_Dir_Grid &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; Flow_Dir_Grid &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; '&lt;SPAN class="comment token"&gt;#' or not Flow_Dir_Grid:&lt;/SPAN&gt;
 Flow_Dir_Grid &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Fdr"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# provide a default value if unspecified&lt;/SPAN&gt;
 
 Watershed_Layer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;3&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; Watershed_Layer &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; '&lt;SPAN class="comment token"&gt;#' or not Watershed_Layer:&lt;/SPAN&gt;
 Watershed_Layer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Watershed"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# provide a default value if unspecified&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# (Iterate Feature Selection):&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# Create a cursor that cycles through all the values in the Shapefile&lt;/SPAN&gt;
 rows &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Watershed_Layer&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 count &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;#&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# #Start the loop&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; rows&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# get the value of JOIN_ID for the current row&lt;/SPAN&gt;
 desc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;getValue&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Name"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# print(desc)&lt;/SPAN&gt;
 input_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Watershed_"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; desc
 output_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"LongestFlowPath_"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; desc
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"The layer name that is input to the longest flow path is: "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; input_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"The resulting output is named: "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; output_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureLayer_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Watershed_Layer&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; input_name&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Name='"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;desc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"'"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 out_loc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\\"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; output_name
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Longest path result output location: "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; out_loc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# The following inputs are layers or table views: "Soucook_watershed_HUC10_DEM_LiDAR", "Fdr", "Watershed_1"&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;LongestFlowpath_geohms&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;in_dem_raster&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;DEM&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
 in_flowdir_raster &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; Flow_Dir_Grid&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
 in_subbasin_features &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; input_name&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
 out_longestflowpath_features &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; out_loc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Longest Flowpath Iter "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;count&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;" successful!"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 output_list&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;output_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# increment the counter&lt;/SPAN&gt;
 row &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; rows&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;next
 count &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; count &lt;SPAN class="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;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The test data set I am using is a feature class that has two polygons, and two polyline feature classes are created, but instead of each feature class just having the one polyline for the respective polygon, they both have both. How can I ensure that each resulting polyline feature class only has a single polyline, for a single polygon, in it?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;**Edit:**&lt;/P&gt;&lt;P&gt;I have just tried this code, which creates separate feature classes, each having only one polygon, and then feeds each feature class into the Longest Flowpath Tool. Somehow it still creates within each result all the polylines from as many polygons as are in the original class, somehow ignoring the fact that each single feature class it is read only has one polygon.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# import stuff&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
 
 &lt;SPAN class="comment token"&gt;# import HEC-GeoHMS toolbox&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ImportToolbox&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcToolbox\Toolboxes\GeoHMS Tools.tbx"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# set environments&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;extent &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"MAXOF"&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;overwriteOutput &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"TRUE"&lt;/SPAN&gt;
 
 
 DEM &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; DEM &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; '&lt;SPAN class="comment token"&gt;#' or not DEM:&lt;/SPAN&gt;
 DEM &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"agreedem"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# provide a default value if unspecified&lt;/SPAN&gt;
 
 Flow_Dir_Grid &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; Flow_Dir_Grid &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; '&lt;SPAN class="comment token"&gt;#' or not Flow_Dir_Grid:&lt;/SPAN&gt;
 Flow_Dir_Grid &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Fdr"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# provide a default value if unspecified&lt;/SPAN&gt;
 
 Watershed_Layer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;3&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; Watershed_Layer &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; '&lt;SPAN class="comment token"&gt;#' or not Watershed_Layer:&lt;/SPAN&gt;
 Watershed_Layer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Watershed"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# provide a default value if unspecified&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# (Iterate Feature Selection):&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# Create a cursor that cycles through all the values in the Shapefile&lt;/SPAN&gt;
 rows &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Watershed_Layer&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 input_list &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
 output_list &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
 lfp_output_list &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
 
 final_output_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; Watershed_Layer &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"_LongestFlowPaths_Merged"&lt;/SPAN&gt;
 
 count &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;#&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# #Start the loop&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; rows&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# get the value of "Name" for the current row&lt;/SPAN&gt;
 desc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;getValue&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Name"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 input_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Watershed_"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; desc
 output_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"LongestFlowPath_"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; desc
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"The layer name that is input to the longest flow path is: "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; input_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"The resulting output is named: "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; output_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureLayer_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Watershed_Layer&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; input_name&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Name='"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;desc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"'"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 out_loc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\\"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; input_name
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Longest path result output location: "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; out_loc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# Write the selected features to a new featureclass&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;CopyFeatures_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;input_name&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; input_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 input_list&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;input_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 output_list&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;output_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# increment the counter&lt;/SPAN&gt;
 row &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; rows&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;next
 count &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; count &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
 
 
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Done creating features - now generating longest flow paths."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; input_watershed&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; output_nam &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; zip&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;input_list&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;output_list&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 
 out_loc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\\Layers\\"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; output_nam
 
 lfp_output_list&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;out_loc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# The following inputs are layers or table views: "Soucook_watershed_HUC10_DEM_LiDAR", "Fdr", "Watershed_1"&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;LongestFlowpath_geohms&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;in_dem_raster&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;DEM&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
 in_flowdir_raster&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;Flow_Dir_Grid&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
 in_subbasin_features&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;input_watershed&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
 out_longestflowpath_features&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;out_loc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Longest Flowpath Iter "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;count&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;" successful!"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍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t;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt; &lt;BR /&gt;Picture of the two longest flowpaths that result from running one watershed (3789) through the tool, despite the layer only having a single polygon. The original layer it was created from has both polygons (3789 and 3791), and the tool seems to be latching onto this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&lt;IMG alt="" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/309643_FCAny.png" style="width: 620px; height: 425px;" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 14:47:40 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-12-11T14:47:40Z</dc:date>
    <item>
      <title>Using Hec-GeoHMS Longest Flowpath Tool within For loop</title>
      <link>https://community.esri.com/t5/water-resources-questions/using-hec-geohms-longest-flowpath-tool-within-for/m-p/309247#M1467</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a feature class made of hundreds of polygons, that I need to determine the longest flow path for using HEC-GeoHMS. As anyone who has used this tool knows, you can't just pass the toolset the entire feature class if any of the watersheds overlap - it will not correctly calculate the longest flowpath for overlapping basins.&lt;/P&gt;&lt;P&gt;So, I am trying to setup a script that iterates through each record in my feature class and generates a longest flow path result for each record separately.&lt;/P&gt;&lt;P&gt;Here is my script so far:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# import stuff&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
 
 &lt;SPAN class="comment token"&gt;# import HEC-GeoHMS toolbox&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ImportToolbox&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcToolbox\Toolboxes\GeoHMS Tools.tbx"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# set environments&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;extent &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"MAXOF"&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;overwriteOutput &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"TRUE"&lt;/SPAN&gt;
 
 DEM &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; DEM &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; '&lt;SPAN class="comment token"&gt;#' or not DEM:&lt;/SPAN&gt;
 DEM &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"agreedem"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# provide a default value if unspecified&lt;/SPAN&gt;
 
 Flow_Dir_Grid &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; Flow_Dir_Grid &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; '&lt;SPAN class="comment token"&gt;#' or not Flow_Dir_Grid:&lt;/SPAN&gt;
 Flow_Dir_Grid &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Fdr"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# provide a default value if unspecified&lt;/SPAN&gt;
 
 Watershed_Layer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;3&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; Watershed_Layer &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; '&lt;SPAN class="comment token"&gt;#' or not Watershed_Layer:&lt;/SPAN&gt;
 Watershed_Layer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Watershed"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# provide a default value if unspecified&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# (Iterate Feature Selection):&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# Create a cursor that cycles through all the values in the Shapefile&lt;/SPAN&gt;
 rows &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Watershed_Layer&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 count &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;#&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# #Start the loop&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; rows&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# get the value of JOIN_ID for the current row&lt;/SPAN&gt;
 desc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;getValue&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Name"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# print(desc)&lt;/SPAN&gt;
 input_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Watershed_"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; desc
 output_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"LongestFlowPath_"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; desc
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"The layer name that is input to the longest flow path is: "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; input_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"The resulting output is named: "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; output_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureLayer_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Watershed_Layer&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; input_name&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Name='"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;desc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"'"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 out_loc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\\"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; output_name
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Longest path result output location: "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; out_loc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# The following inputs are layers or table views: "Soucook_watershed_HUC10_DEM_LiDAR", "Fdr", "Watershed_1"&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;LongestFlowpath_geohms&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;in_dem_raster&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;DEM&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
 in_flowdir_raster &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; Flow_Dir_Grid&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
 in_subbasin_features &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; input_name&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
 out_longestflowpath_features &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; out_loc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Longest Flowpath Iter "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;count&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;" successful!"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 output_list&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;output_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# increment the counter&lt;/SPAN&gt;
 row &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; rows&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;next
 count &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; count &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/S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line feature classes are created, but instead of each feature class just having the one polyline for the respective polygon, they both have both. How can I ensure that each resulting polyline feature class only has a single polyline, for a single polygon, in it?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;**Edit:**&lt;/P&gt;&lt;P&gt;I have just tried this code, which creates separate feature classes, each having only one polygon, and then feeds each feature class into the Longest Flowpath Tool. Somehow it still creates within each result all the polylines from as many polygons as are in the original class, somehow ignoring the fact that each single feature class it is read only has one polygon.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# import stuff&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
 
 &lt;SPAN class="comment token"&gt;# import HEC-GeoHMS toolbox&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ImportToolbox&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcToolbox\Toolboxes\GeoHMS Tools.tbx"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# set environments&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;extent &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"MAXOF"&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;overwriteOutput &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"TRUE"&lt;/SPAN&gt;
 
 
 DEM &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; DEM &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; '&lt;SPAN class="comment token"&gt;#' or not DEM:&lt;/SPAN&gt;
 DEM &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"agreedem"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# provide a default value if unspecified&lt;/SPAN&gt;
 
 Flow_Dir_Grid &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; Flow_Dir_Grid &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; '&lt;SPAN class="comment token"&gt;#' or not Flow_Dir_Grid:&lt;/SPAN&gt;
 Flow_Dir_Grid &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Fdr"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# provide a default value if unspecified&lt;/SPAN&gt;
 
 Watershed_Layer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;3&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; Watershed_Layer &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; '&lt;SPAN class="comment token"&gt;#' or not Watershed_Layer:&lt;/SPAN&gt;
 Watershed_Layer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Watershed"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# provide a default value if unspecified&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# (Iterate Feature Selection):&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# Create a cursor that cycles through all the values in the Shapefile&lt;/SPAN&gt;
 rows &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Watershed_Layer&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 input_list &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
 output_list &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
 lfp_output_list &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
 
 final_output_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; Watershed_Layer &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"_LongestFlowPaths_Merged"&lt;/SPAN&gt;
 
 count &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;#&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# #Start the loop&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; rows&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# get the value of "Name" for the current row&lt;/SPAN&gt;
 desc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;getValue&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Name"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 input_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Watershed_"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; desc
 output_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"LongestFlowPath_"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; desc
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"The layer name that is input to the longest flow path is: "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; input_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"The resulting output is named: "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; output_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureLayer_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Watershed_Layer&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; input_name&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Name='"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;desc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"'"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 out_loc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\\"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; input_name
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Longest path result output location: "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; out_loc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# Write the selected features to a new featureclass&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;CopyFeatures_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;input_name&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; input_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 input_list&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;input_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 output_list&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;output_name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# increment the counter&lt;/SPAN&gt;
 row &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; rows&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;next
 count &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; count &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
 
 
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Done creating features - now generating longest flow paths."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; input_watershed&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; output_nam &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; zip&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;input_list&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;output_list&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 
 out_loc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;workspace &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\\Layers\\"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; output_nam
 
 lfp_output_list&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;out_loc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="comment token"&gt;# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script&lt;/SPAN&gt;
 &lt;SPAN class="comment token"&gt;# The following inputs are layers or table views: "Soucook_watershed_HUC10_DEM_LiDAR", "Fdr", "Watershed_1"&lt;/SPAN&gt;
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;LongestFlowpath_geohms&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;in_dem_raster&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;DEM&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
 in_flowdir_raster&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;Flow_Dir_Grid&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
 in_subbasin_features&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;input_watershed&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
 out_longestflowpath_features&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;out_loc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Longest Flowpath Iter "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;count&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;" successful!"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&l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&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt; &lt;BR /&gt;Picture of the two longest flowpaths that result from running one watershed (3789) through the tool, despite the layer only having a single polygon. The original layer it was created from has both polygons (3789 and 3791), and the tool seems to be latching onto this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&lt;IMG alt="" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/309643_FCAny.png" style="width: 620px; height: 425px;" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:47:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/water-resources-questions/using-hec-geohms-longest-flowpath-tool-within-for/m-p/309247#M1467</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-11T14:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using Hec-GeoHMS Longest Flowpath Tool within For loop</title>
      <link>https://community.esri.com/t5/water-resources-questions/using-hec-geohms-longest-flowpath-tool-within-for/m-p/309248#M1468</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could you please format your code so it is a bit more legible on the forum?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting"&gt;https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jan 2017 21:26:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/water-resources-questions/using-hec-geohms-longest-flowpath-tool-within-for/m-p/309248#M1468</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2017-01-26T21:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using Hec-GeoHMS Longest Flowpath Tool within For loop</title>
      <link>https://community.esri.com/t5/water-resources-questions/using-hec-geohms-longest-flowpath-tool-within-for/m-p/309249#M1469</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Edited.&amp;nbsp; Sorry about that.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jan 2017 21:38:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/water-resources-questions/using-hec-geohms-longest-flowpath-tool-within-for/m-p/309249#M1469</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2017-01-26T21:38:55Z</dc:date>
    </item>
  </channel>
</rss>

