<?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: add a vertex to multiple polylines in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/add-a-vertex-to-multiple-polylines/m-p/287268#M22198</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you Filip, this looks great.&amp;nbsp; I will test it out as soon as I get the chance.&amp;nbsp; Thank you for your help, I will let you know if it works out.&amp;nbsp; Matt&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I had to tweak it a little.&amp;nbsp; Three things to note:&amp;nbsp; arcpy.CreateFeatureclass - lower case c @ (C)lass, had to drop getValue(0) from shp to get it to work(?), and had to define the firstPoint/lastPoint before using that to define p0/p2(not sure that was necessary).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import os, arcpy

in_fc = arcpy.GetParameterAsText(0)
shift_by = 2.0 # shift distance in linear units of your PROJECTED (!) coordinate system

def shiftPointInDirection(x, y, direction, shiftDistance):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Return new (x, y) as shifted x, y in direction (dx, dy) by distance shiftDistance"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; d = (direction[0]**2 + direction[1]**2)**(0.5)
&amp;nbsp;&amp;nbsp;&amp;nbsp; q = shiftDistance / d
&amp;nbsp;&amp;nbsp;&amp;nbsp; x =&amp;nbsp; x + q * direction[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; y = y + q * direction[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp; return (x, y)

# create a new polyline feature class and add field(s)
out_fc = arcpy.CreateFeatureclass_management("Y:/GIS/Working/Test", "test.shp", "POLYLINE", spatial_reference = arcpy.Describe(in_fc).spatialReference).getOutput(0)
arcpy.AddField_management(out_fc, "ORIGID", "LONG")

# starting an edit session may not be necessary, but to stay on the safe side...
workspace = os.path.dirname(in_fc)
with arcpy.da.Editor(workspace) as edit:

&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(in_fc, ["SHAPE@", "OID@"]) as sc:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.InsertCursor(out_fc, ["SHAPE@", "ORIGID"]) as ic:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in sc:
# if your geometries are simple 2D singlepart lines, something like this
# should get the actual line vertices of a feature (sorry don't have Arc now to test)
# search Reading Geometries and Writing Geometries in help
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shp = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; firstPoint = shp.firstPoint
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lastPoint = shp.lastPoint
# handle individual vertices
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p0 = firstPoint
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p2 = lastPoint
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x1,y1 = p0.X, p0.Y
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shift_dir = (p2.X - p0.X, p2.Y - p0.Y)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x1,y1 = shiftPointInDirection(x1, y1, shift_dir, shift_by)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p1 = arcpy.Point(x1, y1)
# create new feature and store it
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_geometry = arcpy.Polyline(arcpy.Array([p0, p1, p2]))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_row = [new_geometry, row[1]]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ic.insertRow(new_row)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 13:53:08 GMT</pubDate>
    <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
    <dc:date>2021-12-11T13:53:08Z</dc:date>
    <item>
      <title>add a vertex to multiple polylines</title>
      <link>https://community.esri.com/t5/python-questions/add-a-vertex-to-multiple-polylines/m-p/287266#M22196</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a lot of lines in a feature class where the only vertices are the two end points.&amp;nbsp; I want to add one vertex 2 ft from the start point of the line.&amp;nbsp; I might be doing something wrong, but the Densify tool doesn't seem like it can pull this off.&amp;nbsp; Any suggestions would be very helpful.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Feb 2014 15:31:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-vertex-to-multiple-polylines/m-p/287266#M22196</guid>
      <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
      <dc:date>2014-02-04T15:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: add a vertex to multiple polylines</title>
      <link>https://community.esri.com/t5/python-questions/add-a-vertex-to-multiple-polylines/m-p/287267#M22197</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Matt,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;How about something like the code below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It assumes projected coordinate system and that all your lines are longer than the shift_by distance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You might need to fix a row or two though cause I haven't tested exactly these lines.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Filip.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;in_fc = r'c:\temp.gdb\infc' out_fc = r'c:\temp.gdb\outfc' shift_by = 2.0 # shift distance in linear units of your PROJECTED (!) coordinate system&amp;nbsp; import os, arcpy&amp;nbsp; def shiftPointInDirection(x, y, direction, shiftDistance): &amp;nbsp;&amp;nbsp;&amp;nbsp; """Return new (x, y) as shifted x, y in direction (dx, dy) by distance shiftDistance""" &amp;nbsp;&amp;nbsp;&amp;nbsp; d = (direction[0]**2 + direction[1]**2)**(0.5) &amp;nbsp;&amp;nbsp;&amp;nbsp; q = shiftDistance / d &amp;nbsp;&amp;nbsp;&amp;nbsp; x =&amp;nbsp; x + q * direction[0] &amp;nbsp;&amp;nbsp;&amp;nbsp; y = y + q * direction[1] &amp;nbsp;&amp;nbsp;&amp;nbsp; return (x, y)&amp;nbsp; # create a new polyline feature class and add field(s) out_fc = arcpy.CreateFeatureClass_management(os.path.dirname(out_fc), os.path.basename(out_fc), "POLYLINE", spatial_reference = arcpy.Describe(in_fc).spatialReference).getOutput(0) arcpy.AddField_management(out_fc, "ORIGID", "LONG")&amp;nbsp; # starting an edit session may not be necessary, but to stay on the safe side... with arcpy.da.Editor(workspace) as edit:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(in_fc, ["SHAPE@", "OID@"]) as sc: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.InsertCursor(out_fc, ["SHAPE@", "ORIGID"]) as ic: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in sc:&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;&amp;nbsp; # if your geometries are simple 2D singlepart lines, something like this &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; # should get the actual line vertices of a feature (sorry don't have Arc now to test) &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; # search Reading Geometries and Writing Geometries in help &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shp = row[0].getPart(0)&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;&amp;nbsp; # handle individual vertices &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; p0 = shp.firstPoint &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; p2 = shp.lastPoint &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; x1,y1 = p0.X, p0.Y &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; shift_dir = (p2.X - p0.X, p2.Y - p0.Y) &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; x1,y1 = shiftPointInDirection(x1, y1, shift_dir, shift_by) &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; p1 = arcpy.Point(x1, y1)&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;&amp;nbsp; # create new feature and store it &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; new_geometry = arcpy.Polyline(arcpy.Array([p0, p1, p2])) &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; new_row = [new_geometry, row[1]] &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; ic.insertRow(newrow)&amp;nbsp; # then join attributes from in_fc to out_fc on in_fc.OBJECTID = out_fc.ORIGID&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Feb 2014 21:53:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-vertex-to-multiple-polylines/m-p/287267#M22197</guid>
      <dc:creator>FilipKrál</dc:creator>
      <dc:date>2014-02-04T21:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: add a vertex to multiple polylines</title>
      <link>https://community.esri.com/t5/python-questions/add-a-vertex-to-multiple-polylines/m-p/287268#M22198</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you Filip, this looks great.&amp;nbsp; I will test it out as soon as I get the chance.&amp;nbsp; Thank you for your help, I will let you know if it works out.&amp;nbsp; Matt&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I had to tweak it a little.&amp;nbsp; Three things to note:&amp;nbsp; arcpy.CreateFeatureclass - lower case c @ (C)lass, had to drop getValue(0) from shp to get it to work(?), and had to define the firstPoint/lastPoint before using that to define p0/p2(not sure that was necessary).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import os, arcpy

in_fc = arcpy.GetParameterAsText(0)
shift_by = 2.0 # shift distance in linear units of your PROJECTED (!) coordinate system

def shiftPointInDirection(x, y, direction, shiftDistance):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Return new (x, y) as shifted x, y in direction (dx, dy) by distance shiftDistance"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; d = (direction[0]**2 + direction[1]**2)**(0.5)
&amp;nbsp;&amp;nbsp;&amp;nbsp; q = shiftDistance / d
&amp;nbsp;&amp;nbsp;&amp;nbsp; x =&amp;nbsp; x + q * direction[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; y = y + q * direction[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp; return (x, y)

# create a new polyline feature class and add field(s)
out_fc = arcpy.CreateFeatureclass_management("Y:/GIS/Working/Test", "test.shp", "POLYLINE", spatial_reference = arcpy.Describe(in_fc).spatialReference).getOutput(0)
arcpy.AddField_management(out_fc, "ORIGID", "LONG")

# starting an edit session may not be necessary, but to stay on the safe side...
workspace = os.path.dirname(in_fc)
with arcpy.da.Editor(workspace) as edit:

&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(in_fc, ["SHAPE@", "OID@"]) as sc:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.InsertCursor(out_fc, ["SHAPE@", "ORIGID"]) as ic:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in sc:
# if your geometries are simple 2D singlepart lines, something like this
# should get the actual line vertices of a feature (sorry don't have Arc now to test)
# search Reading Geometries and Writing Geometries in help
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shp = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; firstPoint = shp.firstPoint
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lastPoint = shp.lastPoint
# handle individual vertices
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p0 = firstPoint
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p2 = lastPoint
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x1,y1 = p0.X, p0.Y
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shift_dir = (p2.X - p0.X, p2.Y - p0.Y)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x1,y1 = shiftPointInDirection(x1, y1, shift_dir, shift_by)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p1 = arcpy.Point(x1, y1)
# create new feature and store it
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_geometry = arcpy.Polyline(arcpy.Array([p0, p1, p2]))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_row = [new_geometry, row[1]]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ic.insertRow(new_row)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:53:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-a-vertex-to-multiple-polylines/m-p/287268#M22198</guid>
      <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
      <dc:date>2021-12-11T13:53:08Z</dc:date>
    </item>
  </channel>
</rss>

