我正在编写一个代码,在我的nhlroster.shp功能类中,nhl球员只需要打这三个位置中的一个:leftFeild、rightFeild、Center,所有球员都必须出生在瑞典。我的arcpy.SelectLayerByLocation\u管理:运行时错误:对象:执行工具中的错误
import arcpy
arcpy.env.workspace = "C:/Users/jessi/Desktop/CPSUGeog485/project3_2021"
cntryFc = "Countries_WGS84.shp"
leftFeild = "LW"
rightFeild = "RW"
Center = "C"
cntryFeild = "CNTRY_name"
cntry = "Sweden"
#Select only players from target country
whereClause = cntryFeild + " = '" + cntry + "'"
cntryLayer = arcpy.SelectLayerByAttribute_management(cntryFc, "NEW_SELECTION", whereClause)
#Create Loop for Target Positions
positionList = (leftFeild, rightFeild, Center)
for plyrPositions in positionList:
playerQuery = "plyrPosition = '" + plyrPositions + "'"
#Narrow down players born in sweden who play target positions
plyrLayer = arcpy.SelectLayerByLocation_management(cntryLayer, "Contains", positionList)
您需要使用arcpy.MakeFeatureLayer_management()将shapefile设置为要素层,如按位置选择https://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/select-layer-by-location.htm和按属性选择文档https://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/select-layer-by-attribute.htm的用法文档中所述;在“按属性选择”行中,“新选择”应为“新选择”
相关问题 更多 >
编程相关推荐