<?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: Centroidal Longest Flowpath (Not GeoHMS) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/centroidal-longest-flowpath-not-geohms/m-p/184696#M14237</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/migrated-users/4495"&gt;Peter Wilson&lt;/A&gt; ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The &lt;EM&gt;Polyline::&lt;/EM&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;EM&gt;queryPointAndDistance (in_point, {as_percentage})&lt;/EM&gt; returns a tuple with the projected point on the line. and the percentage or length (depending the as_percentage parameter) of that point on the line. The documentation is not clear on how the tuple is constructed and in which order the results are listed, but I'll do a small test and get back to you on that.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;If you have the length or percentage the &lt;EM&gt;Polyline::&lt;/EM&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;EM&gt;segmentAlongLine (start_measure, end_measure, {use_percentage})&lt;/EM&gt; can be used to extract the polyline corresponding to the Longest Flow Path.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Kind regards, Xander&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Jul 2015 18:24:27 GMT</pubDate>
    <dc:creator>XanderBakker</dc:creator>
    <dc:date>2015-07-12T18:24:27Z</dc:date>
    <item>
      <title>Centroidal Longest Flowpath (Not GeoHMS)</title>
      <link>https://community.esri.com/t5/python-questions/centroidal-longest-flowpath-not-geohms/m-p/184693#M14234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've re-written my ArcHydro models (Model Builder) into Python and the only part of my model that I've note been able to convert is the Centroidal Longest Flowpath within the Basin Characteristics Toolbox. The explanation under the HEC-GeoHMS user manual (&lt;A href="http://www.hec.usace.army.mil/software/hec-geohms/documentation/HEC-GeoHMS_Users_Manual_10.1.pdf"&gt;HEC-GeoHMS Manual&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"This operation computes the centroidal longest flowpath by projecting the centroid onto the longest flowpath. The centroidal longest flowpath is measured from the projected point onto the longest flowpath to the subbasin outlet as shown in Figure 9-13"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="CentroidalLongestFlowPath.JPG" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/116898_CentroidalLongestFlowPath.JPG" style="width: 620px; height: 550px;" /&gt;&lt;/P&gt;&lt;P&gt;I've searched the internet and have not been able to find an alternative solution to replace the following tool found within the HEC-GeoHMS : Basin Characteristics Toolbox. I'm hoping that someone within the ESRI community have found an alternative script or has written a script to achieve the same functionality as the HEC-GeoHMS: Centroidal Longest Flowpath.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any advice in how to write a python function to replace the following HEC-GeoHMS: Centroidal Longest Flowpath would really be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Peter Wilson&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Jul 2015 21:34:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/centroidal-longest-flowpath-not-geohms/m-p/184693#M14234</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2015-07-11T21:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: Centroidal Longest Flowpath (Not GeoHMS)</title>
      <link>https://community.esri.com/t5/python-questions/centroidal-longest-flowpath-not-geohms/m-p/184694#M14235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Let me see if I understand this correctly, you have:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Input Subbasin&lt;/LI&gt;&lt;LI&gt;Input Centroid&lt;/LI&gt;&lt;LI&gt;Input Longest Flow Path&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;... and the tools creates:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Output Centroidal Longest Flow Path&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess the Centroid is used to select the Subbasin which on it's turn is used to select the longest flow path(s) that correspond to that subbasin. You will probably want to select the nearest flow path (?) and project the point onto this line. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To project the point on the line the :&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-classes/polyline.htm"&gt;arcpy.Polyline()&lt;/A&gt;.queryPointAndDistance (in_point, {as_percentage})&lt;/P&gt;&lt;P&gt;... offers the functionality for this. It will find the point on the polyline nearest to the centroid and return a tuple with among others "the distance along the line where the nearest point occurs". This in combination with the length of the line can be used to determine the Longest Flow Path.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Jul 2015 00:19:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/centroidal-longest-flowpath-not-geohms/m-p/184694#M14235</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-07-12T00:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: Centroidal Longest Flowpath (Not GeoHMS)</title>
      <link>https://community.esri.com/t5/python-questions/centroidal-longest-flowpath-not-geohms/m-p/184695#M14236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Xander&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for getting back to me. Would it be possible&amp;nbsp; to generate a new feature based on the projection of the point onto the longest flow path. I'm struggling to figure out how I would either split the existing line and keep the segment below the points position or generate a new polyline up to the points position. Any suggestions would be appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Jul 2015 12:45:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/centroidal-longest-flowpath-not-geohms/m-p/184695#M14236</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2015-07-12T12:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: Centroidal Longest Flowpath (Not GeoHMS)</title>
      <link>https://community.esri.com/t5/python-questions/centroidal-longest-flowpath-not-geohms/m-p/184696#M14237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/migrated-users/4495"&gt;Peter Wilson&lt;/A&gt; ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The &lt;EM&gt;Polyline::&lt;/EM&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;EM&gt;queryPointAndDistance (in_point, {as_percentage})&lt;/EM&gt; returns a tuple with the projected point on the line. and the percentage or length (depending the as_percentage parameter) of that point on the line. The documentation is not clear on how the tuple is constructed and in which order the results are listed, but I'll do a small test and get back to you on that.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;If you have the length or percentage the &lt;EM&gt;Polyline::&lt;/EM&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;EM&gt;segmentAlongLine (start_measure, end_measure, {use_percentage})&lt;/EM&gt; can be used to extract the polyline corresponding to the Longest Flow Path.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Kind regards, Xander&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Jul 2015 18:24:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/centroidal-longest-flowpath-not-geohms/m-p/184696#M14237</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-07-12T18:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Centroidal Longest Flowpath (Not GeoHMS)</title>
      <link>https://community.esri.com/t5/python-questions/centroidal-longest-flowpath-not-geohms/m-p/184697#M14238</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, so if you use a snippet like this one:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy

&amp;nbsp;&amp;nbsp;&amp;nbsp; fc_pnt = r"C:\Forum\LongestFlowPath\data.gdb\centroid"
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc_lin = r"C:\Forum\LongestFlowPath\data.gdb\flowpath"

&amp;nbsp;&amp;nbsp;&amp;nbsp; # get the first point and first polyline
&amp;nbsp;&amp;nbsp;&amp;nbsp; point = [r[0] for r in arcpy.da.SearchCursor(fc_pnt, ("SHAPE@"))][0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; polyline = [r[0] for r in arcpy.da.SearchCursor(fc_lin, ("SHAPE@"))][0]

&amp;nbsp;&amp;nbsp;&amp;nbsp; # get the tuple
&amp;nbsp;&amp;nbsp;&amp;nbsp; tpl = polyline.queryPointAndDistance(point, False)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print tpl

if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It will return:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;(&amp;lt;PointGeometry object at 0x2233e70[0x2233480]&amp;gt;, 590.9600881822321, 190.0152317659558, True)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Which means: &lt;EM&gt;(point on line, distance from start, distance to line, bool right side of line)&lt;/EM&gt;, which makes sense, since it is the same as ArcObjects does.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To expand the code to extract the longest flow path you can do this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy

&amp;nbsp;&amp;nbsp;&amp;nbsp; fc_pnt = r"C:\Forum\LongestFlowPath\data.gdb\centroid"
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc_lin = r"C:\Forum\LongestFlowPath\data.gdb\flowpath"

&amp;nbsp;&amp;nbsp;&amp;nbsp; # get the first point and first polyline
&amp;nbsp;&amp;nbsp;&amp;nbsp; point = [r[0] for r in arcpy.da.SearchCursor(fc_pnt, ("SHAPE@"))][0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; polyline = [r[0] for r in arcpy.da.SearchCursor(fc_lin, ("SHAPE@"))][0]

&amp;nbsp;&amp;nbsp;&amp;nbsp; # get the tuple
&amp;nbsp;&amp;nbsp;&amp;nbsp; tpl = polyline.queryPointAndDistance(point, False)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # to extract the part from the point on the line to the end:
&amp;nbsp;&amp;nbsp;&amp;nbsp; lfp = polyline.segmentAlongLine(tpl[1], polyline.length, False)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management([lfp], r"C:\Forum\LongestFlowPath\data.gdb\lfp")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # point on line
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management([tpl[0]], r"C:\Forum\LongestFlowPath\data.gdb\projected_pnt")

if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what it looks like:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/116953_pastedImage_9.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:22:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/centroidal-longest-flowpath-not-geohms/m-p/184697#M14238</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T09:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Centroidal Longest Flowpath (Not GeoHMS)</title>
      <link>https://community.esri.com/t5/python-questions/centroidal-longest-flowpath-not-geohms/m-p/184698#M14239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;It's worth emphasising that the method&lt;/SPAN&gt; &lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;segmentAlongLine &lt;SPAN style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"&gt;returns the polyline segment between start and end measure on a &lt;SPAN style="text-decoration: underline;"&gt;single&lt;/SPAN&gt; polyline. If the river is composed of polylines joining at nodes which is typical of say a geometric network it could not return a segment that followed the river downstream beyond it's To-end. If Peter wanted a line that went beyond the end of a polyline he either has to prepare the main stem by dissolving the polylines into a single route&amp;nbsp; and use your code or traverse a network.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jul 2015 16:27:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/centroidal-longest-flowpath-not-geohms/m-p/184698#M14239</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2015-07-15T16:27:13Z</dc:date>
    </item>
  </channel>
</rss>

