HOW TO
Obwohl ArcGIS Pro das Werkzeug "Parallel kopieren" bereitstellt, ist dieses Werkzeug nicht über ArcPy verfügbar.Alternativ kann ein Python-Skript verwendet werden, um einen ähnlichen Effekt wie in der folgenden Abbildung zu erzielen. Ein Skript kann für Workflows in Zusammenhang mit Pipelines, Straßen und Schnellstraßen nützlich und effizient sein.
In diesem Artikel wird die Vorgehensweise beim Verwenden eines Python-Skripts beschrieben, mit dem parallele Features gezeichnet werden.
Hinweis: Dieses Skript kann nicht bei Linienüberschneidungen verwendet werden.
import os, arcpy, math
infc=r'<Feature/Shapefile_Path>' workspace = os.path.dirname(infc) edit = arcpy.da.Editor(workspace)
edit.startEditing(False,True) edit.startOperation()
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))
del cursor edit.stopOperation() edit.stopEditing(True)
Nachfolgend finden Sie das vollständige Skript:
import os, arcpy, math infc=r'C:\Users\User\Desktop\Work\Sample\Test_Shapefile.shp' workspace = os.path.dirname(infc) edit = arcpy.da.Editor(workspace) edit.startEditing(False,True) edit.startOperation() 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)) del cursor edit.stopOperation() edit.stopEditing(True)
Hilfe von ArcGIS-Expert*innen erhalten
Die Esri Support-App herunterladen