Solved! Go to Solution.
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 import os, arcpy def shiftPointInDirection(x, y, direction, shiftDistance): """Return new (x, y) as shifted x, y in direction (dx, dy) by distance shiftDistance""" d = (direction[0]**2 + direction[1]**2)**(0.5) q = shiftDistance / d x = x + q * direction[0] y = y + q * direction[1] return (x, y) # 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") # starting an edit session may not be necessary, but to stay on the safe side... with arcpy.da.Editor(workspace) as edit: with arcpy.da.SearchCursor(in_fc, ["SHAPE@", "OID@"]) as sc: with arcpy.da.InsertCursor(out_fc, ["SHAPE@", "ORIGID"]) as ic: 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 shp = row[0].getPart(0) # handle individual vertices p0 = shp.firstPoint p2 = shp.lastPoint x1,y1 = p0.X, p0.Y shift_dir = (p2.X - p0.X, p2.Y - p0.Y) x1,y1 = shiftPointInDirection(x1, y1, shift_dir, shift_by) p1 = arcpy.Point(x1, y1) # create new feature and store it new_geometry = arcpy.Polyline(arcpy.Array([p0, p1, p2])) new_row = [new_geometry, row[1]] ic.insertRow(newrow) # then join attributes from in_fc to out_fc on in_fc.OBJECTID = out_fc.ORIGID
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 import os, arcpy def shiftPointInDirection(x, y, direction, shiftDistance): """Return new (x, y) as shifted x, y in direction (dx, dy) by distance shiftDistance""" d = (direction[0]**2 + direction[1]**2)**(0.5) q = shiftDistance / d x = x + q * direction[0] y = y + q * direction[1] return (x, y) # 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") # starting an edit session may not be necessary, but to stay on the safe side... with arcpy.da.Editor(workspace) as edit: with arcpy.da.SearchCursor(in_fc, ["SHAPE@", "OID@"]) as sc: with arcpy.da.InsertCursor(out_fc, ["SHAPE@", "ORIGID"]) as ic: 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 shp = row[0].getPart(0) # handle individual vertices p0 = shp.firstPoint p2 = shp.lastPoint x1,y1 = p0.X, p0.Y shift_dir = (p2.X - p0.X, p2.Y - p0.Y) x1,y1 = shiftPointInDirection(x1, y1, shift_dir, shift_by) p1 = arcpy.Point(x1, y1) # create new feature and store it new_geometry = arcpy.Polyline(arcpy.Array([p0, p1, p2])) new_row = [new_geometry, row[1]] ic.insertRow(newrow) # then join attributes from in_fc to out_fc on in_fc.OBJECTID = out_fc.ORIGID
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): """Return new (x, y) as shifted x, y in direction (dx, dy) by distance shiftDistance""" d = (direction[0]**2 + direction[1]**2)**(0.5) q = shiftDistance / d x = x + q * direction[0] y = y + q * direction[1] 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: with arcpy.da.SearchCursor(in_fc, ["SHAPE@", "OID@"]) as sc: with arcpy.da.InsertCursor(out_fc, ["SHAPE@", "ORIGID"]) as ic: 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 shp = row[0] firstPoint = shp.firstPoint lastPoint = shp.lastPoint # handle individual vertices p0 = firstPoint p2 = lastPoint x1,y1 = p0.X, p0.Y shift_dir = (p2.X - p0.X, p2.Y - p0.Y) x1,y1 = shiftPointInDirection(x1, y1, shift_dir, shift_by) p1 = arcpy.Point(x1, y1) # create new feature and store it new_geometry = arcpy.Polyline(arcpy.Array([p0, p1, p2])) new_row = [new_geometry, row[1]] ic.insertRow(new_row)