2017-01-22 8 views
-2

私の指示を選択層を使用していくつかの問題を持つ:は場所の構文で

  • ワークスペース
  • ためのユーザー入力を取得
  • を開始します

    以下

    Create a Python script that selects parcels from "coa_parcels.shp" that intersect with the shapefile "floodplains.shp" and creates a new shapefile that only contains the selected parcels.

    The location of the workspace and the three shapefiles (coa_parcels, floodplains, and the output) should be treated as user-defined inputs using "raw_input" statements.

    は、この部分のためのスクリプトのための擬似コードは一例です

  • 入力フィーチャクラス名(例:coa_parcels.shp)のユーザ入力を取得
  • 選択フィーチャクラス名(例:出力フィーチャクラス名のfloodplains.shp)
  • ゲットユーザー入力(例えばselected_pa​​rcels.shp)は
  • は、ワークスペースを設定し、出力設定を上書き
  • に基づいて、場所によって層からの一時的な機能層
  • 選択を作成します。選択機能クラス
  • コピー新しいフィーチャクラス
  • 印刷ユーザーをさせるメッセージに選択した機能新しいフィーチャクラスが作成されたことを知っている
  • エンド

マイスクリプト:

import arcpy 

workSpace = raw_input("What is the workspace location? ") 
inFeature = raw_input("What is the input feature class name? ") 
selFeature = raw_input("What is the select feature class name? ") 
outFeature = raw_input("What is the output feature class name? ") 

arcpy.env.workspace = workSpace 
arcpy.env.overwriteOutput = True 
arcpy.MakeFeatureLayer_management("coa_parcels.shp", "lyr") 
arcpy.SelectLayerByLocation_management(coa_parcels.shp,"INTERSECT",floodplains.shp, "NEW_SELECTION") 
arcpy.CopyFeatures_management("lyr", "selected_parcels") 
print "A new feature class",outFeature,"has been created!"here 

私のエラーはこれです:NameError:名 'coa_parcels' が

+1

"name 'coa_parcels'が定義されていません"は自明です。他の出現を見ると、おそらく識別子ではなく文字列でなければなりません(=あなたは引用符を忘れてしまいます)。 –

答えて

-1

が定義されていないと、エラーがスローされたラインをよく見て:

arcpy.SelectLayerByLocation_management(coa_parcels.shp, 

レイヤ名を引用符で囲んでいないため、Pythonには、場所によってレイヤを選択するためのパラメータとして変数coa_parcelsを使用する必要があることが示されています。


迷惑な、と自分のエラーとは無関係の、メイクフィーチャレイヤツールは、シェープファイルを作成しません。レイヤー名に.shpを含めることはできませんが(これはエラーが発生していない場所であるためです)、「ベストプラクティス」ではレイヤーをもっとはっきりと指定することをお勧めします。シェイプファイルのみを受け入れるツール。

+0

印刷エラーの問題に本格的な回答を投稿しないでください。再利用価値はありません。 –

関連する問題