0

I need to create one parallel line for each of my 800 line segments and used this method (code below) to successfully create two parallels. The answer mentions the need to separate them into separate parts but doesn't explain how. How can I convert these into one single parallel for each original polyline?

import arcpy, math
infc=r'..\SCRARCH\clone.shp'

def CopyParallel(plyP,sLength):
    part=plyP.getPart(0)
    lArray=arcpy.Array();rArray=arcpy.Array()
    for ptX in part:
        dL=plyP.measureOnLine(ptX)
        ptX0=plyP.positionAlongLine (dL-0.01).firstPoint
        ptX1=plyP.positionAlongLine (dL+0.01).firstPoint
        dX=float(ptX1.X)-float(ptX0.X)
        dY=float(ptX1.Y)-float(ptX0.Y)
        lenV=math.hypot(dX,dY)
        sX=-dY*sLength/lenV;sY=dX*sLength/lenV
        leftP=arcpy.Point(ptX.X+sX,ptX.Y+sY)
        lArray.add(leftP)
        rightP=arcpy.Point(ptX.X-sX, ptX.Y-sY)
        rArray.add(rightP)
    array = arcpy.Array([lArray, rArray])
    section=arcpy.Polyline(array)
    return section


with arcpy.da.UpdateCursor(infc,("Shape@","Width")) as cursor:
    for shp,w in cursor:
        twoLines=CopyParallel(shp,w)
        cursor.updateRow((twoLines,w))

Edited to show a screenshot of what I'm working with. Black is original lines and purple are the offset parallels. enter image description here

4
  • Are the parallell line pairs touching eachother?
    – BERA
    Jul 20, 2021 at 14:55
  • 1
    The lines are not touching their own pairs, although some are intersecting other lines. Edited to add screenshot.
    – ElizaC
    Jul 20, 2021 at 15:10
  • I would try Multipart To Singlepart
    – BERA
    Jul 20, 2021 at 15:11
  • That works to make everything a single part. I should clarify I only want one of these parallels for each original line to remain. How should I go about deleting one of each pair?
    – ElizaC
    Jul 20, 2021 at 15:24

1 Answer 1

1

remove from the script the part that creates ones of the parallels and you are done.

I will start working removing this:

rightP=arcpy.Point(ptX.X-sX, ptX.Y-sY)
        rArray.add(rightP)

to prevent the creation of the "right parallel"

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.