方法
ArcGIS Pro では、ポイント → ライン (Points to Line) ツールを使用して、ポイント フィーチャをライン フィーチャに接続できます。 場合によっては、ポイント フィーチャのグループから、別のポイント フィーチャクラス内の選択したポイントへの接続ラインを配置する必要があります。 ただし、ポイント → ライン (Points to Line) ツールを使用すると、生成されたラインは、次の図に示すように、同じポイント フィーチャクラスのポイントにのみ接続されます。
次の手順では、ArcPy を使用して、フィーチャクラス内のポイントを別のフィーチャクラス内の 1 つのポイント フィーチャにラインでプログラムによって接続する方法を示します。
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>")
以下のコード ブロックに、完全なスクリプトを示します。
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")
以下の図は、ポイント フィーチャのグループを別のフィーチャクラス内の選択したポイント フィーチャに接続するライン フィーチャを示しています。
記事 ID: 000029537
ArcGIS エキスパートのサポートを受ける
Esri Support アプリのダウンロード