Make Feature Layer (Data Management)

Summary

Creates a feature layer from an input feature class or layer file. The layer that is created by the tool is temporary and will not persist after the session ends unless the layer is saved to disk or the map document is saved.

Usage

Syntax

MakeFeatureLayer_management (in_features, out_layer, {where_clause}, {workspace}, {field_info})
ParameterExplanationData Type
in_features

The input feature class or layer used the make the new layer. Complex feature classes, such as annotation and dimensions, are not valid inputs to this tool.

Feature Layer
out_layer

The name of the feature layer to be created. The newly created layer can be used as input to any geoprocessing tool that accepts a feature layer as input.

Feature Layer
where_clause
(Optional)

An SQL expression used to select a subset of features. The syntax for the expression differs slightly depending on the data source. For example, if you're querying file or ArcSDE geodatabases, shapefiles, or coverages, enclose field names in double quotes:

"MY_FIELD"

If you're querying personal geodatabases, enclose fields in square brackets:

[MY_FIELD]

In Python, strings are enclosed in matching single or double quotes. To create a string that contains quotes (as is common with a WHERE clause in SQL expressions), you can escape the quotes (using a backslash) or triple quote the string. For example, if the intended WHERE clause is

"CITY_NAME" = 'Chicago'

you could enclose the entire string in double quotes, then escape the interior double quotes like this:

" \"CITY_NAME\" = 'Chicago' "

Or you could enclose the entire string in single quotes, then escape the interior single quotes like this:

' "CITY_NAME" = \'Chicago\' '

Or you could enclose the entire string in triple quotes without escaping:

""" "CITY_NAME" = 'Chicago' """

For more information on SQL syntax and how it differs between data sources, see the help topic SQL reference for query expressions used in ArcGIS.

SQL Expression
workspace
(Optional)

The input workspace used to validate the field names. If the input is a geodatabase table and the output workspace is a dBASE table, the field names may be truncated, since dBASE fields can only have names of ten characters or less. The new names may be reviewed and altered using the field information control.

Workspace;Feature Dataset
field_info
(Optional)

Can be used to review and alter the field names and hide a subset of fields in the output layer. A split policy can be specified. See the usages for more information.

Field Info

Code Sample

MakeFeatureLayer Example 1 (Python Window)

The following Python window script demonstrates how to use the MakeFeatureLayer function in immediate mode.

import arcpy

arcpy.env.workspace = "C:/data/input"
arcpy.MakeFeatureLayer_management("parcels.shp", "parcels_lyr")



MakeFeatureLayer example 2 (stand-alone script)

The following stand-alone script demonstrates how to use MakeFeatureLayer to create a layer that can be used by SelectLayerByLocation and SelectLayerByAttribute tools.

# Name: ExtractFeaturesByLocationAndAttribute.py
# Description:  Extracts features to a new feature class based on a location and an attribute query.

# Import system modules
import arcpy
from arcpy import env

# Set overwrite option
arcpy.env.overwriteOutput = True

# Put in error trapping in case an error occurs when running tool
try:

   # Make a layer from the feature class
   arcpy.MakeFeatureLayer_management("C:/data/mexico.gdb/cities","cities_lyr")

   # Select all cities that overlap the chihuahua polygon
   arcpy.SelectLayerByLocation_management("cities_lyr", "INTERSECT", "c:/data/mexico.gdb/chihuahua", "", "NEW_SELECTION")

   # Within the selection (done above) further select only those cities that have a population >10,000
   arcpy.SelectLayerByAttribute_management("cities_lyr", "SUBSET_SELECTION", "POPULATION > 10000")

   # Write the selected features to a new featureclass
   arcpy.CopyFeatures_management("cities_lyr", "c:/data/mexico.gdb/chihuahua_10000plus")

except:
   print arcpy.GetMessages()

Environments

Related Topics

Licensing Information

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes

10/27/2014