无法 select 为 arcpy 中给定的多边形输入分层

unable to select layer for a given polygon input in arcpy

我已经创建了 python 脚本工具,并且能够通过提供如下功能 类 来 select 分层。

import arcpy

arcpy.env.workspace = "C:/project/pmms.gdb"

arcpy.SelectLayerByLocation_management('stops', 'intersect', 'adminarea')

但是当我使用下面的代码获取用户输入的多边形(FeatureSet)时,它失败并给出错误消息。我创建了一个 FeatureSet 类型的参数,以允许用户提供交互式多边形输入。请提供您的建议。

import arcpy

fc = "C:/project/pmms.gdb/stops"

infeat = arcpy.GetParameterAsText(0)

arcpy.SelectLayerByLocation_management(fc, 'intersect', infeat)

错误信息:

Traceback (most recent call last):
  File "C:\project\scripts\select.py", line 7, in <module>
    arcpy.SelectLayerByLocation_management(fc, 'intersect', infeat)
  File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\management.py", line 6585, in SelectLayerByLocation
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000368: Invalid input data.
Failed to execute (SelectLayerByLocation).

来自 ArcGIS help page on the Select Layer By Location function:

The input must be a feature layer; it cannot be a feature class.

在尝试 select 之前包含一个 Make Feature Layer 操作,它应该会按预期工作。

fc = "C:/project/pmms.gdb/stops"
arcpy.MakeFeatureLayer_management(fc, 'stops')
arcpy.SelectLayerByLocation_management('stops', 'intersect', infeat)

只需确保您的 ArcMap table 内容层中没有名为 stops 的图层(这可能是您的代码的先前版本能够正常工作的原因)。