Problem with arcpy.describe

3672
8
Jump to solution
08-11-2015 04:58 AM
by Anonymous User
Not applicable

Dear all

I am facing the next problem:

- I have a feature datasatet and a table in a geodatabase, both with the same name (lets say "object1"). It seems not to be any restriction for this.

- However, when I try to get the description (arcpy.Describe) using this common name "object1" I always get the description of the feature dataset and I am not able to access to the description of the table.....

Is there any workaround?

Thank you in advance

Jesús de Diego

0 Kudos
1 Solution

Accepted Solutions
BlakeTerhune
MVP Regular Contributor

With this in mind, you could either rename your geodatabase table and dataset so they are unique, or make a table view of the table using a where clause that will not return any rows (for speed/performance) and do a describe on the view.

where_clause = "1=0"  ## Intentionally will not return any rows
arcpy.MakeTableView_management(inTable, "outTableView", where_clause)
descView = arcpy.Describe("outTableView")
print descView.name, descView.datasetType

View solution in original post

8 Replies
WesMiller
Regular Contributor III

Is your table inside your dataset with the same name? You need to provide the full path "database\dataset\table"

0 Kudos
by Anonymous User
Not applicable

Hi Wes

I believe that tables can't be added to feature datasets....Anyway, in my case, the table is outside any feature dataset.

Following your path example:

Path for the table:

"Database\Table"

Path for the Feature Dataset:

"Database\Feature Dataset"

.... the same....

Thank you anyway

Jesús de Diego

0 Kudos
XanderBakker
Esri Esteemed Contributor

True, tables do not have spatial data and cannot be stored in a feature Dataset. I would recommend renaming the table and make sure that all the elements in your gdb have a unique name. Also if you would want to start a cursor on the table, it will not find the table (since it will encounter the feature dataset with that name first) and throws an error.

Zeke
by
Regular Contributor III

I didn't think you could have any elements with the same name in a gdb.

0 Kudos
XanderBakker
Esri Esteemed Contributor

In fact you can:

... and:

... but you can't have a table and a featureclass with the same name or have two featureclasses with the same name although the reside in different feature datasets.

The Describe functionality can be applied to both the featureclass and the feature dataset:

>>> desc1 = arcpy.Describe(r"D:\Xander\GeoNet\Describe\test2.gdb\SomeName")
>>> desc1.datasetType
u'FeatureDataset'
>>> desc2 = arcpy.Describe(r"D:\Xander\GeoNet\Describe\test2.gdb\SomeName\SomeName")
>>> desc2.datasetType
u'FeatureClass'

... for the table and feature dataset, you can't since they are referenced the same way. If the Featureclass would reside outside the feature dataset, the same would apply for the featureclass, not being able to be described:

>>> desc3 = arcpy.Describe(r"D:\Xander\GeoNet\Describe\test.gdb\Information")
>>> desc3.datasetType
u'FeatureDataset'
BlakeTerhune
MVP Regular Contributor

With this in mind, you could either rename your geodatabase table and dataset so they are unique, or make a table view of the table using a where clause that will not return any rows (for speed/performance) and do a describe on the view.

where_clause = "1=0"  ## Intentionally will not return any rows
arcpy.MakeTableView_management(inTable, "outTableView", where_clause)
descView = arcpy.Describe("outTableView")
print descView.name, descView.datasetType
XanderBakker
Esri Esteemed Contributor

If renaming the table is not an option than the snippet provided by Blake T will offer the best solution.

JoshuaBixby
MVP Esteemed Contributor

Not saying this is any better than Blake T​'s approach, but there is an arcpy.Describe only approach:

gdb = #path to geodatabase
for child in arcpy.Describe(gdb).children:
    if child.name == 'someName' and child.datasetType == 'Table':
        desc = child
        break