1

My code:

import arcpy, csv, os

# Create a Describe object

gdb = r"Database Connections\GISUSER.sde"
desc = arcpy.Describe(gdb)

full_path = False # Specify whether dataset name should be full or relative

# Print some Describe Object properties
if hasattr(desc, "name"):
    print "Name:        " + desc.name   #Prints: GISUSER.sde
if hasattr(desc, "dataType"):
    print "DataType:    " + desc.dataType   #Prints:Workspace
if hasattr(desc, "catalogPath"):
    print "CatalogPath: " + desc.catalogPath  #prints:Database Connections\GISUSER.sde

# Examine children and print their name and dataType and their children's name and dataType
print "\n"  
print "{},\t{},\t{}".format("Children:","Children.Child","DataType") #header
for child in desc.children:
    print "{},\t\t{}".format(child.name,child.dataType)

    #featureDatasets/folders = [child] 
    #so that means Feature classes or subfolders materials = child.children =ds
    for ds in datasets: 
        print "\t{},\t{},\t{},\t{},".format(
            ds.catalogPath.replace("" if full_path else gdb + os.path.sep, ""),
            ds.datatype,
            shapeType = str(ds.catalogPath.shapetype) #WHERE I GET MY ERROR
         )

enter image description here

I want to add another column after DataType for DataShape/telling the user if its a polygon/point/annotation/polyline/etc.

But then I get the error message:

Runtime error 
Traceback (most recent call last):
  File "<string>", line 40, in <module>
AttributeError: 'unicode' object has no attribute 'shapeType'

Describe Object
This code I adapted(shown) does gives me the ShapeType which shows that Shapetype would work for this purpose if I could get past this error.

import arcpy
import os

arcpy.env.workspace = r"Database Connections\GISUSER.sde"

datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else []

for ds in datasets:
    for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
        path = os.path.join(arcpy.env.workspace, ds, fc)
        print(path)
        shapeType = arcpy.Describe(path).shapeType
        print (shapeType)


Results:
Database Connections\GISUSER.sde\Layers.GISUSER.Street_LightsCP
Point
Database Connections\GISUSER.sde\Layers.SDE.penny_parcel
Polygon
Database Connections\GISUSER.sde\Layers.SDE.Subdivision_Circuits
Polygon
Database Connections\GISUSER.sde\Layers.SDE.waterlines2
Polyline
Database Connections\GISUSER.sde\Layers.SDE.Parks_old
Polygon
Database Connections\GISUSER.sde\Layers.SDE.Trails_old
Polyline
Database Connections\GISUSER.sde\layers.SDE.StSenateDstrcts
Polygon
Database Connections\GISUSER.sde\layers.SDE.StHouseDstrct
Polygon
Database Connections\GISUSER.sde\layers.SDE.USHouseRep
Polygon

Basically, I'm trying to Print out all the FeatureDatasetes,Classes, tables, rasterbands and their type , inside a database.

  • 2
    ds.catalogPath returns a string so ds.catalogPath.shapetype will not work. – Paul Apr 24 at 22:31
  • The SDE user shouldn't ever own/manage user data. Doing so puts your database at elevated risk of corruption. Best practice is to create at least one login to own common resources, the grant other users access to these tables by roles. – Vince Apr 24 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.