2025-12-19 11:30:35 玩家互动社区

arcpy.management.MakeFeatureLayer(in_features, out_layer, {where_clause}, {workspace}, {field_info})名称说明数据类型in_features用于创建新图层的输入要素类或图层。 复杂要素类(如注记和尺寸)不是有效输入。

Feature Layerout_layer要创建的要素图层的名称。 图层可用作任何接受要素图层作为输入的地理处理工具的输入。

Feature Layerwhere_clause(可选)用于选择要素子集的 SQL 表达式。有关 SQL 语法的详细信息,请参阅帮助主题在 ArcGIS 中使用的查询表达式的 SQL 参考。

如果输入是具有现有定义查询的图层并且使用此参数指定了 where 子句,则两个 where 子句都将与输出图层的 AND 运算符组合。 例如,如果输入图层有一个 ID > 10 的 where 子句并且此参数设置为 ID < 20,则生成图层的 where 子句将为 ID > 10 AND ID < 20。

SQL Expressionworkspace(可选)旧版本:不使用此参数。

ArcGIS Desktop 中,输出字段名将基于该工作空间进行验证。 ArcGIS Pro 中,由于图层不支持与底层数据源不同的字段名称,因此该工具不支持更改字段名称。

Workspace; Feature Datasetfield_info(可选)将包括在输出图层中的输入要素的字段。 您可以通过将字段设置为不可见来将其移除,并且可以将数值字段设置为具有比率分割策略。 不支持重命名字段。

Field Info代码示例MakeFeatureLayer 示例 1(Python 窗口)

以下 Python 窗口脚本演示了如何在即时模式下使用 MakeFeatureLayer 函数。

import arcpy

arcpy.env.workspace = "C:/data/input"

arcpy.management.MakeFeatureLayer("parcels.shp", "parcels_lyr")MakeFeatureLayer 示例 2(独立脚本)以下独立脚本演示了如何使用 MakeFeatureLayer 函数来创建可供 SelectLayerByLocation 和 SelectLayerByAttribute 函数使用的图层。

# Name: makefeaturelayer_example_2.py

# Description: Uses MakeFeatureLayer with custom field info as input to Intersect

# Import system modules

import arcpy

# Set overwrite option

arcpy.env.overwriteOutput = True

# Set data path

cityboundaries = "C:/data/City.gdb/boundaries"

countyboundaries = "C:/data/City.gdb/counties"

# Get the fields from the input

fields = arcpy.ListFields(cityboundaries)

# Create a fieldinfo object

fieldinfo = arcpy.FieldInfo()

# Iterate through the input fields and add them to fieldinfo

for field in fields:

if field.name == "POPULATION":

# Set the Population to have a ratio split policy

fieldinfo.addField(field.name, field.name, "VISIBLE", "RATIO")

else:

fieldinfo.addField(field.name, field.name, "VISIBLE", "NONE")

# Make a layer from the feature class

arcpy.management.MakeFeatureLayer(cityboundaries, "city_boundaries_lyr", fieldinfo)

# Intersect cities and counties, splitting city population proportionally by county

arcpy.analysis.Intersect([["city_boundaries_lyr"],[countyboundaries]], "memory/intersected_city_counties")