Python ExecuteError:错误000561:所选层的关系无效。无法执行(SelectLayerByLocation)
我正在编写一个代码,在我的nhlroster.shp功能类中,nhl球员只需要打这三个位置中的一个:leftFeild、rightFeild、Center,所有球员都必须出生在瑞典。我的arcpy.SelectLayerByLocation\u管理:运行时错误:对象:执行工具中的错误Python ExecuteError:错误000561:所选层的关系无效。无法执行(SelectLayerByLocation),python,loops,cursor,arcgis,arcpy,Python,Loops,Cursor,Arcgis,Arcpy,我正在编写一个代码,在我的nhlroster.shp功能类中,nhl球员只需要打这三个位置中的一个:leftFeild、rightFeild、Center,所有球员都必须出生在瑞典。我的arcpy.SelectLayerByLocation\u管理:运行时错误:对象:执行工具中的错误 import arcpy arcpy.env.workspace = "C:/Users/jessi/Desktop/CPSUGeog485/project3_2021" cntryFc =
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制作成要素层,如按位置选择和按属性选择文档的用法文档中所述;“新建选择”应在“按属性选择”行中显示为“新建选择”。您在leftField和RightField中有一个输入错误。我试图按照建议添加“生成要素图层”,但仍然收到相同的消息:的关系无效(按位置选择)。arcpy.MakeFeatureLayer\u management('nhlrosters.shp','nhlrosters\u lyr')plyrLayer=arcpy.SelectLayerByLocation\u management('nhlrosters\u lyr','Contains',cntryLayer),因此如果countryFc通过make要素图层线变为countryFc\u lyr,然后通过属性进行选择,然后,我认为您需要将countryFc_lyr输入到按位置选择查询中。尝试用countryFc_lyr替换cntryLayer。下次还可以发布您的编辑,以便更容易了解您的位置。我更新了上面的代码,以显示我当前的位置,但我无法通过“按位置选择”部分。在我的代码的这一部分中,我试图缩小我的cntryLayer中包含的瑞典出生的球员的范围,目标位置为左、右和中。