按属性选择图层 (Data Management)
摘要
基于属性查询在图层或表视图中添加、更新或移除选择内容。
用法
语法
SelectLayerByAttribute_management (in_layer_or_view, {selection_type}, {where_clause})
参数 | 说明 | 数据类型 |
in_layer_or_view |
将应用选择的要素图层或表视图。 输入可以是 ArcMap 内容列表中的图层或表视图,也可以是在 ArcCatalog 或脚本中使用“创建要素图层”或“创建表视图”工具创建的图层或表视图。 | Table View; Raster Layer; Mosaic Layer |
selection_type (可选) |
确定如何应用所选内容以及如果已存在已选内容要执行的操作。
| String |
where_clause (可选) |
用于选择记录子集的 SQL 表达式。有关 SQL 语法的详细信息,请参阅帮助主题ArcGIS 中使用的查询表达式的 SQL 参考。 | SQL Expression |
代码实例
按属性选择图层示例(Python 窗口)
以下 Python 窗口脚本演示了如何在即时模式下使用 SelectLayerByAttribute 函数。
import arcpy
arcpy.MakeFeatureLayer_management ("C:/data/data.mdb/states", "stateslyr")
arcpy.SelectLayerByAttribute_management ("stateslyr", "NEW_SELECTION", " [NAME] = 'California' ")
按属性选择图层示例 2(独立脚本)
以下独立脚本显示了如何在工作流中使用 SelectLayerByAttributes 函数,以便根据位置和属性查询提取要素并将其导入一个新要素类中。
# Name: ExtactFeaturesByLocationAndAttribute.py
# Description: Extract features to a new feature class based on a spatial relationships to another layer AND an attribute query
# Import system modules
import arcpy
# Set the workspace
env.workspace = "c:/data/mexico.gdb"
# Make a layer from the feature class
arcpy.MakeFeatureLayer_management("cities", "lyr")
# Select all cities which overlap the chihuahua polygon
arcpy.SelectLayerByLocation_management("lyr", "intersect", "chihuahua", 0, "new_selection")
# Within selected features, further select only those cities which have a population > 10,000
arcpy.SelectLayerByAttribute_management("lyr", "SUBSET_SELECTION", ' "population" > 10000 ')
# Write the selected features to a new featureclass
arcpy.CopyFeatures_management("lyr", "chihuahua_10000plus")
相关主题
许可信息
ArcGIS for Desktop Basic: 是
ArcGIS for Desktop Standard: 是
ArcGIS for Desktop Advanced: 是
5/10/2014