0

I try to insert a line between two lines. End points of lines are in intersection of lines. I use positionAlongLine in arcpy but it interestingly gets coordinates from the first points of referenced lines even if I use shape.positionAlongLine(0.05).lastPoint Also I get 5cm distance but it generated very long lines. The lines created like the picture. Red lines are generated, blue lines are referenced. The result is oposite of what I want. How to acquire a line using positionAlongLine? enter image description here

import arcpy
arcpy.env.workspace = "C:\Users\Asus\Documents\workspace\PROJECTS\output\output_data.gdb"
coords = []
point = arcpy.Point()
array = arcpy.Array()
featureList = []
cursor = arcpy.InsertCursor(r"anahtar_line")
feat = cursor.newRow()

with arcpy.da.SearchCursor("line", ["OBJECTID", "SHAPE@"]) as scursor:
    for row in scursor:
        shape = row[1]
        end = shape.lastPoint
        point.X = end.X
        point.Y = end.Y
        array.add(point)
        d = shape.positionAlongLine(0.05).lastPoint
        point.X = d.X
        point.Y = d.Y
        array.add(point)
        polyline = arcpy.Polyline(array)
        array.removeAll()
        featureList.append(polyline)
        feat.shape = polyline
        cursor.insertRow(feat)
del feat
del cursor
0

I solved it by flipping lines. I appended last and first coordinates into a list. In order to generate one line, I limited it with len(coords).

import arcpy

arcpy.env.workspace = "C:\Users\Asus\Documents\workspace\PROJECTS\SCADA\others\scripts\output\output_data.gdb"
print arcpy.env.workspace
coords = []
point = arcpy.Point()
array = arcpy.Array()
featureList = []
cursor = arcpy.InsertCursor(r"anahtar_line")
feat = cursor.newRow()

with arcpy.da.SearchCursor("line_Selected", ["OBJECTID", "SHAPE@"]) as scursor:
    for row in scursor:
        shape = row[1]
        first = shape.firstPoint
        end = shape.lastPoint
        coords.append([(first.X, first.Y), (end.X, end.Y)])
        if len(coords)>1:
            pass
        else:
            point.X = first.X
            point.Y = first.Y
            array.add(point)
            d = shape.positionAlongLine(0.05).lastPoint
            point.X = d.X
            point.Y = d.Y
            array.add(point)
            polyline = arcpy.Polyline(array)
            array.removeAll()
            featureList.append(polyline)
            feat.shape = polyline
            cursor.insertRow(feat)
    print coords[1][1]
    print coords[0][1]
    print len(coords)
    if coords[1][1] == coords[0][1]:
        arcpy.FlipLine_edit("line_Selected")
del feat
del cursor

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.