フィーチャの削除(Delete Features) (データの管理)
サマリ
入力フィーチャクラスまたはレイヤからフィーチャを削除します。入力が、フィーチャが選択された状態のレイヤの場合は、選択されているフィーチャだけが削除されます。入力がジオデータベース フィーチャクラスまたはシェープファイルの場合、すべてのフィーチャが削除されます。
使用法
-
このツールでは、フィーチャが選択された状態のレイヤを入力として指定すると、選択されているそれらのフィーチャのみが削除されます。フィーチャクラスから特定のフィーチャを削除するには、[フィーチャ レイヤの作成(Make Feature Layer)] ツールを使用するか、フィーチャクラスを ArcMap の画面に追加して、フィーチャクラスをレイヤに変換します。その後、[属性検索(Select Layer By Attribute)] または [空間検索(Select Layer By Location)] ツールを使用するか、ArcMap でマップ レイヤの検索または選択矢印によるフィーチャの選択を行って、選択を適用することができます。
-
このツールは [入力フィーチャ] のジオメトリと属性の両方を削除します。
-
ArcMap で編集セッション中にこのツールを使用しているときは、元に戻す/やり直し機能を使用してフィーチャの削除(Delete Features)操作を元に戻すことができます。
-
フィーチャクラスからすべてのフィーチャを削除したい場合は、フィーチャクラス、またはフィーチャが選択されていないレイヤに対してこのツールを使用します。
-
ArcSDE フィーチャクラスからすべてのフィーチャを削除したい場合は、フィーチャが選択されていない状態の ArcSDE フィーチャクラス(レイヤではない)に対してこのツールを使用し、フィーチャの行ごとの削除ではなくデータベースの切詰めを実行してすべてのフィーチャを削除してください。フィーチャクラスのすべてのフィーチャを削除する場合は、データベースの切詰め操作を行うと処理を高速化できます。
構文
| パラメータ | 説明 | データ タイプ |
in_features |
削除するフィーチャを含むフィーチャクラス、シェープファイル、またはレイヤ。 | Feature Layer |
コードのサンプル
次の Python ウィンドウ スクリプトは、イミディエイト モードで DeleteFeatures(フィーチャの削除)ツールを使用する方法を示しています。
import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.CopyFeatures_management("majorrds.shp", "C:/output/output.gdb/majorrds2")
arcpy.DeleteFeatures_management("C:/output/output.gdb/majorrds2")
次のスタンドアロン スクリプトは、式に基づいてフィーチャを削除するために DeleteFeatures(フィーチャの削除)関数を使用する方法を示しています。
# Name: DeleteFeatures_Example2.py
# Description: Delete features from a feature class based on an expression
# Author: ESRI
# Import system modules
import arcpy
from arcpy import env
# Set environment settings
env.workspace = "C:/data/airport.gdb"
# Set local variables
inFeatures = "parcels"
outFeatures = "C:/output/output.gdb/new_parcels"
tempLayer = "parcelsLayer"
expression = arcpy.AddFieldDelimiters(tempLayer, "PARCEL_ID") + " = 'Cemetery'"
try:
# Execute CopyFeatures to make a new copy of the feature class
arcpy.CopyFeatures_management(inFeatures, outFeatures)
# Execute MakeFeatureLayer
arcpy.MakeFeatureLayer_management(outFeatures, tempLayer)
# Execute SelectLayerByAttribute to determine which features to delete
arcpy.SelectLayerByAttribute_management(tempLayer, "NEW_SELECTION",
expression)
# Execute GetCount and if some features have been selected, then
# execute DeleteFeatures to remove the selected features.
if int(arcpy.GetCount_management(tempLayer).getOutput(0)) > 0:
arcpy.DeleteFeatures_management(tempLayer)
except Exception, e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print "Line %i" % tb.tb_lineno
print e.message