写一个运行于arcgis10.2.2工具箱python2.7的脚本代码:输入要素图层,批量按查询表达式筛选后的要素图层
时间: 2024-01-22 08:20:34 浏览: 200
请参考以下代码:
```python
import arcpy
# 设置工作空间
arcpy.env.workspace = "path/to/workspace"
# 输入要素图层
input_layer = arcpy.GetParameterAsText(0)
# 查询表达式
query_expression = arcpy.GetParameterAsText(1)
# 获取要素类名称
feature_class_name = arcpy.Describe(input_layer).name
# 构建输出要素类名称
output_feature_class_name = feature_class_name + "_filtered"
# 构建 SQL 查询语句
sql_expression = arcpy.AddFieldDelimiters(input_layer, arcpy.Describe(input_layer).OIDFieldName) + " IN (SELECT " + arcpy.AddFieldDelimiters(input_layer, arcpy.Describe(input_layer).OIDFieldName) + " FROM " + feature_class_name + " WHERE " + query_expression + ")"
# 使用 Select_analysis 工具进行查询并保存结果
arcpy.Select_analysis(input_layer, output_feature_class_name, sql_expression)
# 输出结果
arcpy.SetParameterAsText(2, output_feature_class_name)
```
注意:请将 `path/to/workspace` 替换为您的工作空间路径。此脚本需要两个输入参数:1) 输入要素图层;2) 查询表达式。输出结果为按照查询表达式筛选后的要素图层。
阅读全文