我的指示:
创建一个Python脚本,该脚本从“ coa_parcels.shp”中选择与形状文件“ floodplains.shp”相交的地块,并创建一个仅包含所选地块的新shapefile。
应使用“ raw_input”语句将工作空间和三个shapefile(coa_parcels,洪泛区和输出)的位置视为用户定义的输入。
以下是此部分脚本的示例伪代码:
我的剧本:
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'
仔细查看引发错误的行:
arcpy.SelectLayerByLocation_management(coa_parcels.shp,
通过在引号中不包括层名称,您是在向Python指示它应使用变量coa_parcels
作为通过定位工具输入到选择层的参数。
未经请求且与您的错误无关,“制作要素图层”工具不会创建shapefile。没有什么可以阻止您.shp
将图层名称包括在内(显然,因为这不是您的错误发生的地方!),但是对于“最佳实践”,我建议您更明确地命名图层,以免您不小心将图层传递给工具仅接受shapefile。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句