newbie question about feature layer in Python

3899
4
Jump to solution
03-27-2015 12:06 PM
DanielSchatt
New Contributor III

hi all, I'm confused about something.   I just took an ESRI Python course that points out the distinction between feature classes and feature layers, and that some tools require the use of feature layers.  Now I need to clip one polygon feature class to another and the Clip analysis tool seems to be what I need.  The documentation for this tool says that both the "in_features" and the "clip_features" need to be Feature Layers as opposed to Feature Classes.  But in their Clip sample code, they just use shapefiles as is within the tool parameters (code below).

My question is: Why do they NOT need to use the MakeFeatureLayer tool on the in_features and clip_features shapefiles to make Feature Layers for use in the tool?  Thanks!

Dan

# Name: Clip_Example2.py
# Description: Clip major roads that fall within the study area.

# Import system modules
import arcpy
from arcpy import env

# Set workspace
env.workspace = "C:/data"

# Set local variables
in_features = "majorrds.shp"
clip_features = "study_quads.shp"
out_feature_class = "C:/output/studyarea.shp"
xy_tolerance = ""

# Execute Clip
arcpy.Clip_analysis(in_features, clip_features, out_feature_class, xy_tolerance)

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ModyBuchbinder
Esri Regular Contributor

Hi Dan

When the parameter is in_layer it means layer only. When the parameter is in_features it means feature class or feature layer.

I am not sure if it is written anywhere in the docs but parameter that defined as FeatureLayer can be both.

If you use the wizards within ArcMap you see that you can select a layer from ArcMap or navigate to feature class.

View solution in original post

0 Kudos
4 Replies
ModyBuchbinder
Esri Regular Contributor

Hi Dan

FeatureLayer can be a layer in ArcMap or a FeatureClass, no need for MakeFeatureLayer.

A few tools (for example Select Layer By Location) needs only a layer. If you would like to use FeatureClass for them you will need to create a layer from it.

Have Fun

0 Kudos
DanielSchatt
New Contributor III

thanks much Mody! sorry I'm still a little unclear on this.  Now I know this particular tool requirement, but just in general for future reference:  If the documentation states it needs a Feature Layer for input, then how does one know that it only needs a Feature Class?  Maybe another way of stating this questions is:  when writing Python code, when is a Feature Class also a Feature Layer?

0 Kudos
ModyBuchbinder
Esri Regular Contributor

Hi Dan

When the parameter is in_layer it means layer only. When the parameter is in_features it means feature class or feature layer.

I am not sure if it is written anywhere in the docs but parameter that defined as FeatureLayer can be both.

If you use the wizards within ArcMap you see that you can select a layer from ArcMap or navigate to feature class.

0 Kudos
DanielSchatt
New Contributor III

Thanks Mody, that's what I needed!  It would be nice if, just for clarity, they simply listed all acceptable data types for each parameter without assuming any user knowledge.

0 Kudos