ジオプロセシング ツールでのジオメトリ オブジェクトの使用

多くのジオプロセシング ワークフローでは、座標とジオメトリの情報を使用して特定の操作を行うことだけが必要で、新しい(一時)フィーチャクラスを作成し、カーソルを使用してフィーチャクラスにデータを設定し、そのフィーチャクラスを使用し、最後に一時フィーチャクラスを削除するというプロセスをすべて行う必要はないことがあります。ジオプロセシングを簡単に実行できるように、入力および出力の両フィーチャクラスの代わりにジオメトリ オブジェクトを使用できます。GeometryMultipointPointGeometryPolygon、または Polyline の各クラスを使用して、ジオメトリ オブジェクトを最初から作成できます。

入力としてのジオメトリの使用

次のサンプルでは、x,y 座標のリストを使用して、ポリゴン ジオメトリ オブジェクトを作成します。その後、Clip ツールを使用して、ポリゴン ジオメトリ オブジェクトでフィーチャクラスをクリップします。

import arcpy

# Create an Array object.
#
array = arcpy.Array()

# List of coordinates.
#
coordList = ['1.0;1.0','1.0;10.0','10.0;10.0','10.0;1.0']

# For each coordinate set, create a point object and add the x- and 
#   y-coordinates to the point object, then add the point object 
#   to the array object.
#
for coordPair in coordList:
    x, y = coordPair.split(";")
    pnt = arcpy.Point(x,y)
    array.add(pnt)

# Add in the first point of the array again to close the polygon boundary
#
array.add(array.getObject(0))

# Create a polygon geometry object using the array object
#
boundaryPolygon = arcpy.Polygon(array)

# Use the geometry to clip an input feature class
#
arcpy.Clip_analysis("c:/data/rivers.shp", boundaryPolygon, "c:/data/rivers_clipped.shp")

ジオメトリ オブジェクトの出力

空のジオメトリ オブジェクトに対してジオプロセシングツールの出力を設定することによって、出力ジオメトリ オブジェクトを作成できます。出力先を空のジオメトリ オブジェクトに設定してツールを実行すると、ツールはジオメトリ オブジェクトのリストを返します。次の例では、Copy Features ツールを使用してジオメトリ オブジェクトのリストを取得します。このリストをループ処理して、すべてのフィーチャの合計長を累算します。

import arcpy

# Create an empty Geometry object
#
g = arcpy.Geometry()

# Run the CopyFeatures tool, setting the output to the geometry object.  GeometryList
#  is returned as a list of geometry objects.
#  
geometryList = arcpy.CopyFeatures_management("c:/temp/outlines.shp", g)

# Walk through each geometry, totaling the length
#
length = 0
for geometry in geometryList:
    length += geometry.length

print "Total length: %f" % length

関連項目


7/10/2012