HOW TO
In ArcGIS Pro können Punkt-Features mit dem Werkzeug Punkte in Linie mit Linien-Features verbunden werden. In einigen Fällen ist es erforderlich, Verbindungslinien von einer Gruppe von Punkt-Features zu einem ausgewählten Punkt in einer anderen Point-Feature-Class festzulegen. Bei Verwendung des Werkzeugs "Punkte in Linie" werden die generierten Linien jedoch nur mit den Punkten aus derselben Point-Feature-Class verbunden, wie in der folgenden Abbildung dargestellt.
Das folgende Verfahren beschreibt, wie Sie mithilfe von ArcPy programmgesteuert Punkte in einer Feature-Class mit einem einzelnen Punkt-Feature in einer anderen Feature-Class mit Linien verbinden.
import arcpy <VariableName1> = "<PointName1>" <VariableName2> = "<PointName2>" <VariableName3> = "<LineName>"
assert arcpy.management.GetCount(points_layer1)[0] == "1", "select exactly 1 point from <VariableName1>" assert int(arcpy.management.GetCount(points_layer1)[0]) > 0, "select > 0 point(s) from <VariableName2>"
with arcpy.da.SearchCursor(<VariableName1>, ["SHAPE@XY"]) as cursor: for row in cursor: end_x, end_y = row[0] end_point = arcpy.PointGeometry(arcpy.Point(float(end_x), float(end_y)))
if not arcpy.Exists(VariableName3): arcpy.management.CreateFeatureclass(arcpy.env.workspace, "<LineName>", "POLYLINE")
line_array = arcpy.Array() with arcpy.da.SearchCursor(<VariableName2>, ["SHAPE@XY"]) as cursor: for row in cursor: start_x, start_y = row[0] start_point = arcpy.PointGeometry(arcpy.Point(float(start_x), float(start_y)))
line_array.append(start_point.centroid) line_array.append(end_point.centroid)
line = arcpy.Polyline(line_array) line_array.removeAll()
with arcpy.da.InsertCursor(<VariableName3>, ["SHAPE@"]) as icursor: icursor.insertRow([line])
arcpy.management.MakeFeatureLayer(<VariableName3>,"<LineName>")
Im folgenden Code-Block finden Sie das vollständige Skript.
import arcpy points_layer1 = "facilities" points_layer2 = "pts" lines_layer = "lines" assert arcpy.management.GetCount(points_layer1)[0] == "1", "select exactly 1 point from points_layer1" assert int(arcpy.management.GetCount(points_layer1)[0]) > 0, "select > 0 point(s) from points_layer2" with arcpy.da.SearchCursor(points_layer1, ["SHAPE@XY"]) as cursor: for row in cursor: end_x, end_y = row[0] end_point = arcpy.PointGeometry(arcpy.Point(float(end_x), float(end_y))) if not arcpy.Exists(lines_layer): arcpy.management.CreateFeatureclass(arcpy.env.workspace, "lines", "POLYLINE") line_array = arcpy.Array() with arcpy.da.SearchCursor(points_layer2, ["SHAPE@XY"]) as cursor: for row in cursor: start_x, start_y = row[0] start_point = arcpy.PointGeometry(arcpy.Point(float(start_x), float(start_y))) line_array.append(start_point.centroid) line_array.append(end_point.centroid) line = arcpy.Polyline(line_array) line_array.removeAll() with arcpy.da.InsertCursor(lines_layer, ["SHAPE@"]) as icursor: icursor.insertRow([line]) arcpy.management.MakeFeatureLayer(lines_layer,"lines")
Die folgende Abbildung zeigt Linien-Features, die eine Gruppe von Punkt-Features mit einem ausgewählten Punkt-Feature in einer anderen Feature-Class verbinden.
Artikel-ID: 000029537
Unterstützung durch ArcGIS-Experten anfordern
Esri Support App herunterladen