Layers and features classes

289
8
07-20-2017 09:37 AM
BrianRizzo
New Contributor II

Hi Britt!  At the UC we discussed the difference between layer files and feature classes.  Many of the arcpy function calls (like model builder tools!) will not work with feature classes.  As a result when calling a command that requires a layer we are forced to first create one from an existing feature class.  Am I interpreting this correctly or are there 'other' calls that will accept FC's?

This came up today in a call to 

       arcpy.Buffer_analysis(FC2_GDB,FC3,"100 yards")  where FC2_GDB is a GDB feature class.  I get an error input data set is not supported.

Also If I do need to create a layer, are those layers temporary if not can I make them temporary or do I need to delete them later.

Brian

0 Kudos
8 Replies
JoshuaBixby
MVP Esteemed Contributor

The Buffer tool can work directly against feature classes.  I just tested it on my 10.5.1 machine, and I had no problem using it with a feature class in a geodatabase.  Can you provide more specifics about the variables FC2_GDB and FC3?

0 Kudos
BrianRizzo
New Contributor II
 FC2_GDB = "B:\PythonClass\pythonweek2\Exercise1GDB\VaInterStates"
 FC3 =r"B:\PythonClass\pythonweek2\Exercise1GDB\VaInterStatesBuff"
    # buffer interstates 100 yards
    arcpy.Buffer_analysis(FC2_GDB,FC3,"100 yards")
FC2_GDB exists as a GDB feature class.  
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If you are not going to escape the backslashes in path, you should use raw string notation:

FC2_GDB = r"B:\PythonClass\pythonweek2\Exercise1GDB\VaInterStates"
 FC3 =r"B:\PythonClass\pythonweek2\Exercise1GDB\VaInterStatesBuff"

Raw string or not, I think the bigger issue is the FC2_GDB path doesn't seem to be pointing to a file geodatabase or a feature class in a file geodatabase.  File geodatabases have a .gdb suffix to the folder, which I don't see here in either of the paths.  What does your ArcCatalog window look like for the Exercicse1GDB folder?

BrianRizzo
New Contributor II

adding the .gdb extension solved the issue..

But I still have a question about Feature Layers and feature classes.  The buffer tool wants a feature layer as input.  Does this preclude the use of a feature class?

If so, we can create feature layers easy enough MakeFeatureLayer but why the complication?

Thanks for the help!

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

scenario

in arcmap or ArcGIS pro, if you have a feature selected and you run a tool that accepts either a layer or a file on disk (ie featureclass), then there is the option to choose either... the little black downward pointing arrow head allows you to pick a layer from the currently existing layers... buffering (for example) will only buffer the selected features in the layer.

Now... you blew it... you didn't want to make the selection until after you buffered... you could unselect, but instead, you cleverly select the folder icon beside the input featureclass combobox,, and navigate to the file on disk in the geodatabase... in that scenario... all features will be used since the featureclass on disk known nothing about its featurelayer in arcmap.  It remains oblivious to the selection and allows the buffer tool to buffer all.

0 Kudos
BrianRizzo
New Contributor II

this is a very lucid explanation that I will use in my  class! 

However, from a programmatic perspective it would still be nice to have the option of inputting a FC OR a layer for many of the functions that require only layers, but I can see where this can lead to duplication and even confusion.  I can live with layers now that I know why they are used as input.

Brian  

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I can't say I have tested them all, but I would bet a large majority of tools outside of the ArcPy Mapping module that say "Feature Layer" as the Data Type will also take a feature class.  For whatever reason, the tools in the Proximity toolset all seem to say "Feature Layer" while I know I regularly use them with feature classes.  I would say focus on the Explanation more than the Data Type column when determining syntax. 

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Brian... If you make a 'layer' file... the selection will be used, since the reference to the actual file is kept as well as the selection on it... but... you have to make a *.lyr (or lyrx in Pro) to use a selection outside of Arc-whatever.  Confusing, but useful.  My preference is to skip layers (lyr) altogether, actually make a 'real' file (not a reference to plus stuff), use it... keep it or delete it.  in_memory seems to have its place for a lot of people as well... preferences I guess and/or whether you are using *Map or *Pro

0 Kudos