1

I have a polyline feature class that is using GCS_WGS_1984 (code 4326). I am trying to create lines that are parallel to a polyline from this feature class at distance d.

From some searching, I've only been able to find out how to create parallel lines here:

Creating parallel line in ArcGIS Pro using ArcPy?

but it only works for 2D:

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))

I have tried first projecting to spatial reference code 3857, then running the above code, then converting back. However, there is some distortion (~8% error).

Is there a solution that would work for geographic coordinate systems?

6
  • -1 for not mentioning the source.
    – FelixIP
    Nov 25, 2020 at 2:36
  • I've added the source
    – sdMarth
    Nov 25, 2020 at 2:39
  • 2
    Spatial references with projected and geographic coordinate systems should behave very differently. Doing Cartesian math on a geographic CS does not work, and no distance measurement should ever be trusted in Web Mercator. ArcPy provides the tools to perform the Forward and Inverse geodetic problems (PointGeometry methods pointFromAngleAndDistance () and angleAndDistanceTo(), respectively), or you can project to an appropriate projection, then project back). Note that the parallel lines will not look parallel in a GCS (and you may need to densify the line first).
    – Vince
    Nov 25, 2020 at 3:20
  • 1
    Ok. I removed my downvote.
    – FelixIP
    Nov 25, 2020 at 4:03
  • hi @Vince, can you elaborate on why there may be a need to densify?
    – sdMarth
    Nov 25, 2020 at 17:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.