For an existing set of line features, I would like to generate a perpendicular line, of say 1km, at the midpoint of each existing line feature in ArcGIS.
I imagine that The methodology would be to:
- create a tangent line at the midpoint of each existing line feature
- calculate the angle of the tangent line
- based on the angle of the tangent line, calculate the location of the endpoint of the new line
- create the new line with the calculated endpoint of the new line and the existing midpoint of the old line
Let's assume that we are in a UTM projection and can use coordinates to calculate distance and direction.
How would I do this with ArcGIS tools or with ArcPy?
Answer
- Create midpoints, using one of multiple possible techniques.
- Buffer them by small number, e.g. 0.5 m
- Clip originals by buffer, output - SHAPEFILE
Use this field calculator expression on field Shape:
def RotateExtend(plyP,sLength):
l=plyP.length
ptX=plyP.positionAlongLine (l/2).firstPoint
ptX0=plyP.firstPoint
ptX1=plyP.lastPoint
dX=float(ptX1.X)-float(ptX0.X)
dY=float(ptX1.Y)-float(ptX0.Y)
lenV=math.sqrt(dX*dX+dY*dY)
sX=-dY*sLength/lenV;sY=dX*sLength/lenV
leftP=arcpy.Point(ptX.X+sX,ptX.Y+sY)
rightP=arcpy.Point(ptX.X-sX, ptX.Y-sY)
array = arcpy.Array([leftP,rightP])
section=arcpy.Polyline(array)
return section
RotateExtend( !Shape!, 1000)
UPDATE:
Ooops! it creates perpendicular, not tangent. Can be easily modified
No comments:
Post a Comment