<?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 How to keep ID value from original polyline in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-keep-id-value-from-original-polyline/m-p/712015#M55213</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've created the following python script that extracts the position along a polyline based on a user defined interval. The chainage is determined for each point (i.e. first point = 0 ; second point =50m ; 100m ; 150m ; .... last point = 452m) The problem that I have is that it works great for a single polyline but as soon as you have more than one polyline there is no way of knowing the ID (Cross Section ID) that the points were derived from. I'm using the ArcPy Data Access SearchCursor to find the positions along the line based on the user defined interval and then the list of points are used to create a point feature class with the chainage added as a new field. I was orignally helped by someone else with adding the chainge (distance) values to the pts list using the python zip function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need assistance extracting the ID field from the polyline and adding the ID value to a new field within the points feature class that is being created. Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've attached my python script as you can't paste within GeoNET &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/angry.png" /&gt;. The old user forum was so much better.&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, 09 Aug 2014 14:36:08 GMT</pubDate>
    <dc:creator>PeterWilson</dc:creator>
    <dc:date>2014-08-09T14:36:08Z</dc:date>
    <item>
      <title>How to keep ID value from original polyline</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-id-value-from-original-polyline/m-p/712015#M55213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've created the following python script that extracts the position along a polyline based on a user defined interval. The chainage is determined for each point (i.e. first point = 0 ; second point =50m ; 100m ; 150m ; .... last point = 452m) The problem that I have is that it works great for a single polyline but as soon as you have more than one polyline there is no way of knowing the ID (Cross Section ID) that the points were derived from. I'm using the ArcPy Data Access SearchCursor to find the positions along the line based on the user defined interval and then the list of points are used to create a point feature class with the chainage added as a new field. I was orignally helped by someone else with adding the chainge (distance) values to the pts list using the python zip function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need assistance extracting the ID field from the polyline and adding the ID value to a new field within the points feature class that is being created. Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've attached my python script as you can't paste within GeoNET &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/angry.png" /&gt;. The old user forum was so much better.&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, 09 Aug 2014 14:36:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-id-value-from-original-polyline/m-p/712015#M55213</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2014-08-09T14:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep ID value from original polyline</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-id-value-from-original-polyline/m-p/712016#M55214</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="text-align: left;"&gt;Hi&lt;BR /&gt;Peter&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="text-align: left;"&gt;You&lt;BR /&gt;will have to change your program a little.&lt;/P&gt;&lt;P style="text-align: left;"&gt;You&lt;BR /&gt;have to create an empty feature class with the attributes you need (&lt;SPAN lang="EN" style="color: #3d3d3d; font-family: 'Arial','sans-serif'; font-size: 10pt; mso-ansi-language: EN;"&gt;chainge and LineId).&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;SPAN lang="EN" style="color: #3d3d3d; font-family: 'Arial','sans-serif'; font-size: 10pt; mso-ansi-language: EN;"&gt;When you open your cursor to the lines you should get the&lt;BR /&gt;ID too.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;SPAN lang="EN" style="color: #3d3d3d; font-family: 'Arial','sans-serif'; font-size: 10pt; mso-ansi-language: EN;"&gt;Then you write each point separately into the feature&lt;BR /&gt;class and not into geometry list.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;SPAN lang="EN" style="color: #3d3d3d; font-family: 'Arial','sans-serif'; font-size: 10pt; mso-ansi-language: EN;"&gt;This way you can enter the LineId for each point you&lt;BR /&gt;insert.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;SPAN lang="EN" style="color: #3d3d3d; font-family: 'Arial','sans-serif'; font-size: 10pt; mso-ansi-language: EN;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;SPAN lang="EN" style="color: #3d3d3d; font-family: 'Arial','sans-serif'; font-size: 10pt; mso-ansi-language: EN;"&gt;Have fun&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Aug 2014 04:41:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-id-value-from-original-polyline/m-p/712016#M55214</guid>
      <dc:creator>ModyBuchbinder</dc:creator>
      <dc:date>2014-08-10T04:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep ID value from original polyline</title>
      <link>https://community.esri.com/t5/python-questions/how-to-keep-id-value-from-original-polyline/m-p/712017#M55215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Peter,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is an update to your script that creates the feature class, and then inserts the geometry and ID values into the feature class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14077774317606897 jive_text_macro" jivemacro_uid="_14077774317606897"&gt;
&lt;P&gt;outpnts = os.path.join(gdb, os.path.join(gdb, os.path.basename(pipeline) + "_pnts"))&lt;/P&gt;
&lt;P&gt;outpnts = arcpy.CreateFeatureclass_management(gdb, os.path.basename(pipeline) + "_pnts", "POINT", "", "", "", pipeline)&lt;/P&gt;
&lt;P&gt;arcpy.AddField_management(outpnts,"chainage","DOUBLE")&lt;/P&gt;
&lt;P&gt;arcpy.AddField_management(outpnts,"ID","SHORT")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;pts = []&lt;/P&gt;
&lt;P&gt;fields = ["SHAPE@", "ID"]&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;with arcpy.da.SearchCursor(pipeline, fields) as scur:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in scur:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = arcpy.da.InsertCursor(outpnts, fields)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; geometry = row[0]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l = 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while l &amp;lt; geometry.length:&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; pts.append((geometry.positionAlongLine(l), l))&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; pt = (geometry.positionAlongLine(l))&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; row_values = [(pt, row[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; for row in row_values:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.insertRow(row)&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; l += interval&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; leng = geometry.length&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pt = (geometry.positionAlongLine(leng))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pts.append((geometry.positionAlongLine(leng), leng))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row_values = [(pt, row[1])]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in row_values:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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; cursor.insertRow(row)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;del cursor, scur&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;pts, distances = zip(*pts)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;with arcpy.da.UpdateCursor(outpnts,["chainage"]) as cursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; n = 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = distances&lt;N&gt;&lt;/N&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n += 1&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;del cursor&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, &lt;A _jive_internal="true" href="https://community.esri.com/groups/python/blog/2014/07/08/posting-code-blocks-in-the-new-geonet?sr=search&amp;amp;searchId=a928a2d9-e0aa-41ce-b82e-c0efd92fd827&amp;amp;searchIndex=0"&gt;here&lt;/A&gt; is a great post on how to post code in GeoNET.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Aug 2014 17:18:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-keep-id-value-from-original-polyline/m-p/712017#M55215</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2014-08-11T17:18:34Z</dc:date>
    </item>
  </channel>
</rss>

