3

How to set workspace from input Feature Class ? is there an attribute of the source GDB for a feature class ? some times the FC is in a dataset and some time it isn't, How can i get the path of source GDB for setting workspace when the input is dynamic ?

matt wilkie
28.3k35 gold badges150 silver badges286 bronze badges
asked Aug 31, 2014 at 8:15

1 Answer 1

17

Use the catalogPath property of the Describe object.

For example:

dirname = os.path.dirname(arcpy.Describe(feat_class).catalogPath)
desc = arcpy.Describe(dirname)
if hasattr(desc, "datasetType") and desc.datasetType=='FeatureDataset':
 dirname = os.path.dirname(dirname)
answered Aug 31, 2014 at 8:20
4
  • the catalog path function gives the path with the dataset, for setting workspace i need the path to the GDB only (without the data set) Commented Aug 31, 2014 at 8:25
  • @Geog Luke is correct. os.path.dirname() extracts the workspace out of the full path. Commented Aug 31, 2014 at 8:53
  • @Geog Use os.path.dirname twice. See edit. Commented Aug 31, 2014 at 8:58
  • You can also try using the path property of the Describe object: stackoverflow.com/a/36905906/2457991 Commented Apr 28, 2016 at 5:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.