2

In many Esri examples, including this one, they code in the output ".shp". What is the best way if you want to be able to handle a shapefile OR a feature class output. Let say if a GDB is provided as the workspace, then features class, if a folder directory then .shp. Is there any ArcPy built-in to handing this?

4
  • Doesn't matter, you just supply the path to the output featureclass which can be a shapefile featureclass, a file geodatabase featureclass, an enterprise geodatabase featureclass, etc...
    – user2856
    Aug 28, 2020 at 4:45
  • The parent folder just has to be the geodatabase (.sde or .gdb) or a feature dataset in a geodatabase, and the feature class name must not have a .shp suffix.
    – Vince
    Aug 28, 2020 at 6:19
  • For example this ouput will create a shape: r"C:\GIS\data\outputdataset" and this a feature class in a database r"C:\GIS\data\database.gdb\outputdataset". Just leave out the .shp, arcpy will add it if output is a folder
    – BERA
    Aug 28, 2020 at 6:30
  • Good answers thank you.
    – Rex
    Aug 28, 2020 at 14:14

1 Answer 1

3

As commented, it doesnt matter. Just supply the path and ~filename without the .shp extension and arcpy will know what to do.

For example:

  • With a folder named data r"C:\GIS\data\outputdataset" a shape named outputdataset.shp (and all other shape extensions) will be created in it
  • If the output is a database, like a file geodatabase arcpy will create a feature class in it, example: r"C:\GIS\data\database.gdb\outputdataset"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.