1

In an Python Toolbox I have a parameter that gets the location of a geodatabase input.gdb which has several layers of input data.

contextual_data_param = arcpy.Parameter(
 name="context",
 displayName="source for contextual data files",
 datatype="GPFile",
 direction="Input",
 parameterType="Optional"
 )

From that parameter I would like to access feature layers in the .gdb individually.

Appending layer names using os.path.join() hasn't worked because the parameter returns a geoprocessing value rather than a string/path.

Is GPfile the right datatype to be using?

How can I open a feature layer in a geodatabase using the separate names of the feature layer and the geodatabase?

Noura
3,4373 gold badges21 silver badges41 bronze badges
asked Apr 1, 2020 at 16:45
1
  • 2
    A file geodatabase is a DEWorkspace class (the contents of which can be accessed via arcpy.ListFeatureClasses() and ListTables and ListDatasets). See the documentation. I use os.path.join exclusively, so I know it works (if you extract the path with .valueAsText -- note that the value is unicode in Python 2.7), Commented Apr 1, 2020 at 17:13

1 Answer 1

2

File geodatabase is a container class which holds feature classes, feature datasets (which group feature classes), and tables. Python Toolbox parameter class for file geodatabase is DEWorkspace (which also includes directories which contain shapefiles and Enterprise geodatabase connection files (.sde)).

The for a parameter declared like this:


 def getParameterInfo(self):
 contextual_data_param = arcpy.Parameter(
 name="context",
 displayName="source for contextual data files",
 datatype="DEWorkspace",
 direction="Input",
 parameterType="Optional"
 )
 return [contextual_data_param]

The execute function to exploit the collected data might look like

 def execute(self, parameters, messages):
 cdp = parameters[0].valueAsText
 arcpy.env.workspace = cdp
 full_fcs = []
 for fc in arcpy.ListFeatureClasses():
 full_fcs.append(os.path.join(cdp,fc))
 ...

The full list of supported toolbox parameters is documented online (this is Pro, but Desktop has the same options). It's not unusual to have to sift through and choose your best option.

answered Apr 1, 2020 at 19:40

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.