AnsweredAssumed Answered

da Insert cursor writing empy geometry

Question asked by LANDVEST on Sep 27, 2016
Latest reply on Sep 29, 2016 by LANDVEST

I'll preface this by saying I'm pretty weak on cursors but trying to boot camp myself to basic proficiency.


I'm trying to create a simple script that will take a point feature class and create lines from them. These points are the start point of the the line and for sake of demonstration here, the endpoints are defined mathematically from them. Simple 2-point lines.


startingPt = "STARTING_POINTS" #point feature layer in MXD
fields = ['SHAPE@X', 'SHAPE@Y']

point = arcpy.Point()
array = arcpy.Array()

featureList = []
insert = arcpy.da.InsertCursor(r"D:\Temp\Lines.shp",['SHAPE@'])

with arcpy.da.SearchCursor(startingPt, fields) as cursor:
    for row in cursor:
       startX = row[0]
       startY = row[1]
       endX = startX + 660
       endY = startY + 660
       polyline = arcpy.Polyline(array)
       insert = arcpy.da.InsertCursor(r"D:\Temp\Lines.shp",['SHAPE@'])

       print "Start: {},{} End: {},{}".format(startX,startY,endX,endY)
del cursor

The script successfully writes rows to the target, but the geometry is empty. I'm sure there is a simple (and stupid) mistake in the code. Any help is appreciated and I'm totally open to suggestions. I'd rather not have a copy features or append operation but just an insert unless my logic is totally flawed here.