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=-dYsLength/lenV;sY=dXsLength/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?
PointGeometrymethodspointFromAngleAndDistance ()andangleAndDistanceTo(), 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 '20 at 03:20