カーソルの空間参照の設定

フィーチャクラスの空間参照は、そのフィーチャクラスの座標系、空間ドメイン、および精度を記述します。

デフォルトでは、SearchCursor から返されるジオメトリの空間参照は、カーソルによって開かれたフィーチャクラスと同じです。更新カーソルまたは挿入カーソルに空間参照を設定することもできます。

UpdateCursor または InsertCursor に対して空間参照を設定するとき、そのカーソルによって書き込むジオメトリの空間参照を宣言します。たとえば、UTM 座標を使用するフィーチャクラスにジオメトリを挿入したいとします。State Plane 座標を含むテキスト ファイルからジオメトリを読み取って、このフィーチャクラスに挿入します。フィーチャクラスの空間参照(UTM)は、テキスト ファイルから読み取るジオメトリ(State Plane)とは異なります。このフィーチャクラスに対して InsertCursor を開くときには、カーソルの空間参照を State Plane に設定し、挿入するジオメトリを State Plane から UTM に変換するように宣言します。したがって、InsertCursor または UpdateCursor の空間参照を設定する必要があるのは、書き込むジオメトリがカーソルのフィーチャクラスとは別の空間参照を使用しているときだけです。

SearchCursor の場合は、カーソルのフィーチャクラスの空間参照とは異なる空間参照を指定すると、ジオメトリがカーソルの空間参照に変換されます。

次の例では、ポイント フィーチャクラスは座標系 UTM zone 21 north を使用します。この座標系は空間参照で定義されています。このスクリプトは、ポイントの座標を 10 進表記の度で示すテキスト ファイルを生成します。

import arcpy

# Describe a feature class with a geographic coordinate system
#
desc = arcpy.Describe("d:/base/data.gdb/latlongbnd")

# Create search cursor. Use the spatial reference object from the
#   described feature class so geometries are returned in decimal degrees.
#
rows = arcpy.SearchCursor("d:/base/data.gdb/buildings", "", desc.spatialReference)

# Open the file for output. This also creates the file if it does not exist.
#
out = open(arcpy.GetParameterAsText(0), "w")

# Print the coordinates of each building point feature
#
for row in rows:
    # Create the geometry object
    #
    feat = row.shape

    # Get the geometry's point object.
    #
    pnt = feat.getPart()

    # Write the x,y coordinate to the output file
    #
    out.write(pnt.X + ";" + pnt.Y + "\n")

# Close the output file
#
out.close()

関連項目


7/10/2012