<?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: python create polylines with attributes in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-create-polylines-with-attributes/m-p/586583#M46047</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You've found your answer, but in general you can do this by including more fields in your cursor:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt;with arcpy.da.InsertCursor(outputFC, [&lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue; background-color: #f6f6f6;"&gt;"SHAPE@","ID"&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000; background-color: #f6f6f6;"&gt;]) as cursor: # should use 'with' notation&lt;/SPAN&gt;
&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = # the geometry value
&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = # the ID value
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.insertRow(row) # write entire row&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 01:13:43 GMT</pubDate>
    <dc:creator>DarrenWiens2</dc:creator>
    <dc:date>2021-12-12T01:13:43Z</dc:date>
    <item>
      <title>python create polylines with attributes</title>
      <link>https://community.esri.com/t5/python-questions/python-create-polylines-with-attributes/m-p/586581#M46045</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I've used &lt;A href="http://pro.arcgis.com/en/pro-app/arcpy/get-started/writing-geometries.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;the following reference&lt;/A&gt; to create polylines, and it works great, but I'm having trouble figuring out how to attach attribute information with the polyline being drawn. In the script below, I want the "ID" value that's in the coordsList to also be an attribute feature for that polyline.&amp;nbsp; &lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Input Variables
table = r"S:\Rachel\Data\Temp_Fiber_Manhole_Data\Python_Test\TubeRoutes_Test.dbf"
outputFC = r"S:\Rachel\Data\Temp_Fiber_Manhole_Data\Python_Test\test_output.shp"
template = r"S:\Rachel\Data\Temp_Fiber_Manhole_Data\Python_Test\test_template.shp"


#Create List of coordinates (ID, X, Y)
coordsList = []
for row in arcpy.SearchCursor(table):
&amp;nbsp;&amp;nbsp;&amp;nbsp; coordsList.append([row.ID,row.From_XCoor,row.From_YCoor])
&amp;nbsp;&amp;nbsp;&amp;nbsp; coordsList.append([row.ID,row.To_XCoor,row.To_YCoor])
&amp;nbsp;&amp;nbsp;&amp;nbsp; del row


cur = None
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create the output feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFeatureclass_management(os.path.dirname(outputFC),os.path.basename(outputFC), "POLYLINE", template,"","",template)


&amp;nbsp;&amp;nbsp;&amp;nbsp; # Open an insert cursor for the new feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; cur = arcpy.da.InsertCursor(outputFC, ["SHAPE@"])


&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create an array object needed to create features
&amp;nbsp;&amp;nbsp;&amp;nbsp; array = arcpy.Array()


&amp;nbsp;&amp;nbsp;&amp;nbsp; # Initialize a variable for keeping track of a feature's ID.
&amp;nbsp;&amp;nbsp;&amp;nbsp; ID = -1
&amp;nbsp;&amp;nbsp;&amp;nbsp; for coords in coordsList: 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ID == -1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID = coords[0]


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Add the point to the feature's array of points
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #If the conduit bank ID&amp;nbsp; has changed, create a new feature
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ID != coords[0]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cur.insertRow([arcpy.Polyline(array)])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array.removeAll()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array.add(arcpy.Point(coords[1], coords[2], ID=coords[0]))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID = coords[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Add the last feature
&amp;nbsp;&amp;nbsp;&amp;nbsp; cur.insertRow([arcpy.Polyline(array)])




except Exception as e:
&amp;nbsp;&amp;nbsp; print(e)
finally:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Cleanup the cursor if necessary
&amp;nbsp;&amp;nbsp;&amp;nbsp; if cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del cur
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
print "done"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:13:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-create-polylines-with-attributes/m-p/586581#M46045</guid>
      <dc:creator>RachelAlbritton</dc:creator>
      <dc:date>2021-12-12T01:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: python create polylines with attributes</title>
      <link>https://community.esri.com/t5/python-questions/python-create-polylines-with-attributes/m-p/586582#M46046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nevermind - I just realized that I can use the&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/XY_To_Line/0017000000tv000000/"&gt; XY to Line tool&lt;/A&gt; to take care of this issue&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jul 2016 21:39:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-create-polylines-with-attributes/m-p/586582#M46046</guid>
      <dc:creator>RachelAlbritton</dc:creator>
      <dc:date>2016-07-13T21:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: python create polylines with attributes</title>
      <link>https://community.esri.com/t5/python-questions/python-create-polylines-with-attributes/m-p/586583#M46047</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You've found your answer, but in general you can do this by including more fields in your cursor:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt;with arcpy.da.InsertCursor(outputFC, [&lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue; background-color: #f6f6f6;"&gt;"SHAPE@","ID"&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000; background-color: #f6f6f6;"&gt;]) as cursor: # should use 'with' notation&lt;/SPAN&gt;
&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = # the geometry value
&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = # the ID value
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.insertRow(row) # write entire row&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:13:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-create-polylines-with-attributes/m-p/586583#M46047</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-12T01:13:43Z</dc:date>
    </item>
  </channel>
</rss>

