我的指示:
创建一个 Python 脚本,从“coa_parcels.shp”中选择与 shapefile“floodplains.shp”相交的地块,并创建一个仅包含所选地块的新 shapefile。
工作空间的位置和三个 shapefile(coa_parcels、洪泛区和输出)应被视为使用“raw_input”语句的用户定义输入。
下面是这部分脚本的示例伪代码:
- 开始
- 获取工作区的用户输入
- 获取输入要素类名称的用户输入(例如 coa_parcels.shp)
- 获取所选要素类名称的用户输入(例如,floodplains.shp)
- 获取输出要素类名称的用户输入(例如 selected_parcels.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: name 'coa_parcels' is not defined