How do I create parallel lines to the end of the polygon and then clip them with arcpy?
With the script I'm currently using, the lines are not created correctly.
The script I am using is this
import arcpy, math
offset = 3
offset_original = offset
features=[]
arcpy.env.overwriteOutput = True
infc="linha"
talhao = "poligono"
#arcpy.Intersect_analysis([infc, talhao], "AB_Intersect", "ALL", "", "INPUT")
spatialRef = arcpy.Describe(infc).spatialReference
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])
section=arcpy.Polyline(array, spatialRef)
return section
with arcpy.da.UpdateCursor(infc,["SHAPE@"]) as cursor:
for shp in cursor:
i=0
while i <= 200:
if (i == 0):
twoLines=CopyParallel(shp[0],offset)
else:
twoLines=CopyParallel(features[-1],offset)
features.append(twoLines)
i=i+1
arcpy.CopyFeatures_management(features, "teste")
Error