Search code examples
python-2.7objectarcgisarcpy

arcpy: get feature class as object


How do I create an object in python from a feature class in a geodatabase? I would think the following code would create a featureclass object?

featureclassobject = "C:/path/to/my/featureclass"

But this creates a string object, right? So I am not able to pass this object into an arcpy function later on.


Solution

  • You are correct that it creates a string object. However, whether it will work with a particular ArcPy function depends on the function -- in most cases, the tool simply needs to know the path to the function as a string (which the featureclassobject is).

    The help pages are slightly unhelpful in this regard. Buffer, for example, says that input parameter in_features needs to be data type "Feature Layer" -- however, what it really expects is a string that describes where the feature layer can be found.


    One significant exception to this is geometry objects:

    In many geoprocessing workflows, you may need to run a specific operation using coordinate and geometry information but don't necessarily want to go through the process of creating a new (temporary) feature class, populating the feature class with cursors, using the feature class, then deleting the temporary feature class. Geometry objects can be used instead for both input and output to make geoprocessing easier.

    But if you've already got a feature class (or shapefile) on disk, that's much simpler than creating an in-memory geometry object to work with.