使用 python (ArcMap 10.5.1) 将 ArcGIS 中的选定属性导出到新图层?

Exporting selected attributes in ArcGIS to a new layer using python (ArcMap 10.5.1)?

我有一个包含 25 个不同年份数据的文件,我需要将每一年的数据导出到一个新的 shapefile 中。我已经编写了一种 select 文件的方法,但现在我需要帮助将我 select 编辑的那一年的数据导出到新的 shapefile 中。年度 selection 涉及 SelectLayerByAttribute_management 函数,如果这有助于您了解我如何为 selection 编码的话。出于实际目的,只需说我从中提取数据的主文件名为 "Customers",我想将各个年份导出到名为 "Customers_20xx".

的新形状文件中
>>> import arcpy
>>> arcpy.SelectLayerByAttribute_management("Customers", "NEW_SELECTION", "Year=1989")
<Result 'Customers'>

这部分有效。当我输入该代码时,文件 "Customers" 中 1989 年的每个数据集都被 selected。现在只需将 selected 数据导出到名为 "Customers_1989" 的新文件中 – PythonPerson 2 小时前

直接取自http://pro.arcgis.com/en/pro-app/tool-reference/data-management/select-layer-by-attribute.htm

# Import system modules
import arcpy

# Set the workspace
arcpy.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")

最后一行也许就是您要找的那一行。如果您 运行 在具有选区的图层上,将仅导出选定的要素。但是,如果您对特征 class 或 shapefile 执行此操作,所有特征都将被复制。

如果您还没有从要素 class 或 shapefile 制作图层文件,那么我建议您使用 arcpy.MakeFeatureLayer_management("cities", "lyr") 命令来制作图层文件。