6

I am trying to create a json structure that will describe a multitude of different arcpy data types (FeatureClass, FeatureDataset, Workspace, etc). I would like the script to be dynamic and give all possible information for the item that is passed into arcpy.Describe(), and since attributes of a Describe object change based on the input, I need a way to dynamically assign those attributes.

Here's what I've tried:

import arcpy
desc = arcpy.Describe("path\to\thing\being\inspected")

Attempt #1: (based on https://stackoverflow.com/questions/2675028/list-attributes-of-an-object)

desc.__dict__
# returns
AttributeError: DescribeData: Method __dict__ does not exist

Attempt #2: (based on https://stackoverflow.com/questions/2675028/list-attributes-of-an-object#comment19846153_2675148)

vars(desc)
# returns
TypeError: vars() argument must have __dict__ attribute

Attempt #3: (based on https://stackoverflow.com/a/687252/9052438)

dir(desc)
# returns
[]

Attempt #4: (based on https://stackoverflow.com/a/2675542/9052438)

desc.__dir__()
# returns
AttributeError: DescribeData: Method __dir__ does not exist

This all tells me that arcpy.Describe() isn't technically a Python object, but given that, is there still a way to do this without having to hard-code a list of attributes to check based on the dataType?

4
  • 2
    Do you have access to ArcGIS Pro? The .da.Describe (pro.arcgis.com/en/pro-app/arcpy/data-access/describe.htm) is more structured and possibly more helpful in your case than the regular Describe which (quote): properties are dynamic, meaning that depending on what data type is described, different Describe properties are available for use
    – KHibma
    Commented Oct 15, 2019 at 17:59
  • 1
    And arcpy.da.Describe returns a dictionary so is simple to inspect
    – user2856
    Commented Oct 15, 2019 at 20:41
  • I do have access to arcgis pro, but when I try to inspect something, (i.e. when I try to run arcpy.da.Describe(file_path) the function just churns with no output. I left it running for quite a while before giving up. When I figure out what's going on I'll be sure to try this.
    – jesnes
    Commented Oct 15, 2019 at 20:44
  • You have to assign the result to a variable which will be a dictionary of keys and values.
    – KimO
    Commented Oct 31, 2019 at 9:23

2 Answers 2

7

ArcGIS Pro's arcpy.da.Describe(fc) works like this:

all_attr = arcpy.da.Describe('pipe')
import pprint pprint.pprint(all_attr) 
    > {'DSID': 3,  'FIDSet': None, 
    > 'MExtent': '1.#QNAN 1.#QNAN',  'OIDFieldName': 'OBJECTID', 
    > 'TimeZone': '',  'ZExtent': '1.#QNAN 1.#QNAN',  'aliasName': 'pipe', 
    > 'areaFieldName': '',  'baseName': 'pipe',  'canVersion': False, 
    > 'catalogPath': 'G:\\project\\capacity\\capacity\\capacity.gdb\\pipe', 
    > 'changeTracked': False,  'children': [],  'childrenExpanded': True, 
    > 'createdAtFieldName': '',  'creatorFieldName': '',  'dataElement':
    > {'DSID': 3,
    >                  'FIDSet': None,
    >                  'MExtent': '1.#QNAN 1.#QNAN',
    >                  'OIDFieldName': 'OBJECTID',
    >                  'ZExtent': '1.#QNAN 1.#QNAN',
    >                  'aliasName': 'pipe',
    >                  'areaFieldName': '',
    >                  'baseName': 'pipe',
    >                  'canVersion': False,
    >                  'catalogPath': 'G:\\project\\capacity\\capacity\\capacity.gdb\\pipe',
    >                  'changeTracked': False,
    >                  'children': [],
    >                  'childrenExpanded': True,
    >                  'createdAtFieldName': '',
    >                  'creatorFieldName': '',
    >                  'dataElementType': 'DEFeatureClass',
    >                  'dataType': 'FeatureClass',
    >                  'datasetType': 'FeatureClass',
    >                  'defaultSubtypeCode': -1,
    >                  'editedAtFieldName': '',
    >                  'editorFieldName': '',
    >                  'editorTrackingEnabled': False,
    >                  'extension': '',
    >                  'extensionProperties': {},
    >                  'extent': <Extent object at 0x30743128[0x3583c508]>,
    >                  'featureType': 'Simple',
    >                  'fields': [<Field object at 0x307434e0[0x357c48d0]>,
    >                             <Field object at 0x30743668[0x357c4910]>,
    >                             <Field object at 0x30743390[0x357c4970]>,
    >                             <Field object at 0x30743908[0x357c4a30]>,
    >                             <Field object at 0x30743ef0[0x357c4b10]>,
    >                             <Field object at 0x30743518[0x357c48b0]>,
    >                             <Field object at 0x30743a20[0x357c4b90]>,
    >                             <Field object at 0x307435f8[0x357c4c30]>],
    >                  'file': 'pipe',
    >                  'fullPropsRetrieved': True,
    >                  'geometryStorage': '',
    >                  'globalIDFieldName': '',
    >                  'hasGlobalID': False,
    >                  'hasM': False,
    >                  'hasOID': True,
    >                  'hasSpatialIndex': True,
    >                  'hasZ': False,
    >                  'indexes': [<Index object at 0x30743588[0x357c4cb0]>,
    >                              <Index object at 0x30743630[0x357c4d50]>],
    >                  'isCOGOEnabled': False,
    >                  'isTimeInUTC': True,
    >                  'isVersioned': False,
    >                  'lengthFieldName': 'Shape_Length',
    >                  'metadataRetrieved': False,
    >                  'modelName': '',
    >                  'name': 'pipe',
    >                  'path': 'G:\\project\\capacity\\capacity\\capacity.gdb',
    >                  'rasterFieldName': '',
    >                  'relationshipClassNames': [],
    >                  'representations': [],
    >                  'shapeFieldName': 'Shape',
    >                  'shapeType': 'Polyline',
    >                  'spatialReference': <SpatialReference object at 0x307436a0[0x357c4df0]>,
    >                  'subtypeFieldName': '',
    >                  'versionedView': ''},  'dataElementType': 'DEFeatureClass',  'dataType': 'FeatureLayer',  'datasetType':
    > 'FeatureClass',  'defaultSubtypeCode': -1,  'editedAtFieldName': '', 
    > 'editorFieldName': '',  'editorTrackingEnabled': False, 
    > 'endTimeField': '',  'extension': '',  'extensionProperties': {}, 
    > 'extent': <Extent object at 0x30743fd0[0x3583c418]>,  'featureClass':
    > {'DSID': 3,
    >                   'FIDSet': None,
    >                   'MExtent': '1.#QNAN 1.#QNAN',
    >                   'OIDFieldName': 'OBJECTID',
    >                   'ZExtent': '1.#QNAN 1.#QNAN',
    >                   'aliasName': 'pipe',
    >                   'areaFieldName': '',
    >                   'baseName': 'pipe',
    >                   'canVersion': False,
    >                   'catalogPath': 'G:\\project\\capacity\\capacity\\capacity.gdb\\pipe' ,
    >                   'changeTracked': False,
    >                   'children': [],
    >                   'childrenExpanded': True,
    >                   'createdAtFieldName': '',
    >                   'creatorFieldName': '',
    >                   'dataElementType': 'DEFeatureClass',
    >                   'dataType': 'FeatureClass',
    >                   'datasetType': 'FeatureClass',
    >                   'defaultSubtypeCode': -1,
    >                   'editedAtFieldName': '',
    >                   'editorFieldName': '',
    >                   'editorTrackingEnabled': False,
    >                   'extension': '',
    >                   'extensionProperties': {},
    >                   'extent': <Extent object at 0x30743f98[0x3583caa8]>,
    >                   'featureType': 'Simple',
    >                   'fields': [<Field object at 0x30743e80[0x357c4ed0]>,
    >                              <Field object at 0x30743da0[0x357c4830]>,
    >                              <Field object at 0x30743d30[0x35836630]>,
    >                              <Field object at 0x30743cf8[0x358365d0]>,
    >                              <Field object at 0x307437b8[0x358367d0]>,
    >                              <Field object at 0x30743710[0x357c4f50]>,
    >                              <Field object at 0x307436d8[0x35836770]>,
    >                              <Field object at 0x30743cc0[0x35836730]>],
    >                   'file': 'pipe',
    >                   'fullPropsRetrieved': True,
    >                   'geometryStorage': '',
    >                   'globalIDFieldName': '',
    >                   'hasGlobalID': False,
    >                   'hasM': False,
    >                   'hasOID': True,
    >                   'hasSpatialIndex': True,
    >                   'hasZ': False,
    >                   'indexes': [<Index object at 0x30743c50[0x358366f0]>,
    >                               <Index object at 0x30743c18[0x35836690]>],
    >                   'isCOGOEnabled': False,
    >                   'isTimeInUTC': True,
    >                   'isVersioned': False,
    >                   'lengthFieldName': 'Shape_Length',
    >                   'metadataRetrieved': False,
    >                   'modelName': '',
    >                   'name': 'pipe',
    >                   'path': 'G:\\project\\capacity\\capacity\\capacity.gdb',
    >                   'rasterFieldName': '',
    >                   'relationshipClassNames': [],
    >                   'representations': [],
    >                   'shapeFieldName': 'Shape',
    >                   'shapeType': 'Polyline',
    >                   'spatialReference': <SpatialReference object at 0x30743a58[0x35836650]>,
    >                   'subtypeFieldName': '',
    >                   'versionedView': ''},  'featureType': 'Simple',  'fieldInfo': <FieldInfo object at 0x30743828[0x358365f0]>,  'fields':
    > [<Field object at 0x307437f0[0x35836590]>,
    >             <Field object at 0x30743e10[0x35836550]>,
    >             <Field object at 0x30743550[0x358364f0]>,
    >             <Field object at 0x30743198[0x35836030]>,
    >             <Field object at 0x307431d0[0x358360b0]>,
    >             <Field object at 0x30743208[0x35836510]>,
    >             <Field object at 0x30743240[0x35836190]>,
    >             <Field object at 0x30743f28[0x358361f0]>],  'file': 'pipe',  'fullPropsRetrieved': True,  'globalIDFieldName': '', 
    > 'hasGlobalID': False,  'hasM': False,  'hasOID': True, 
    > 'hasSpatialIndex': True,  'hasZ': False,  'indexes': [<Index object at
    > 0x30743b38[0x35836290]>,
    >              <Index object at 0x30743b70[0x35836330]>],  'isCOGOEnabled': False,  'isTimeInUTC': True,  'isVersioned': False, 
    > 'lengthFieldName': 'Shape_Length',  'metadataRetrieved': False, 
    > 'modelName': '',  'name': 'pipe',  'nameString': 'pipe',  'path':
    > 'G:\\project\\capacity\\capacity\\capacity.gdb',  'rasterFieldName':
    > '',  'relationshipClassNames': [],  'representations': [], 
    > 'shapeFieldName': 'Shape',  'shapeType': 'Polyline', 
    > 'spatialReference': <SpatialReference object at
    > 0x307438d0[0x358363b0]>,  'startTimeField': '',  'subtypeFieldName':
    > '',  'table': {'DSID': 3,
    >            'FIDSet': None,
    >            'MExtent': '1.#QNAN 1.#QNAN',
    >            'OIDFieldName': 'OBJECTID',
    >            'ZExtent': '1.#QNAN 1.#QNAN',
    >            'aliasName': 'pipe',
    >            'areaFieldName': '',
    >             'baseName': 'pipe',
    >            'canVersion': False,
    >            'catalogPath': 'G:\\project\\capacity\\capacity\\capacity.gdb\\pipe',
    >            'changeTracked': False,
    >            'children': [],
    >            'childrenExpanded': True,
    >            'createdAtFieldName': '',
    >            'creatorFieldName': '',
    >            'dataElementType': 'DEFeatureClass',
    >            'dataType': 'FeatureClass',
    >            'datasetType': 'FeatureClass',
    >            'defaultSubtypeCode': -1,
    >            'editedAtFieldName': '',
    >            'editorFieldName': '',
    >            'editorTrackingEnabled': False,
    >            'extension': '',
    >            'extensionProperties': {},
    >            'extent': <Extent object at 0x30743978[0x3583c8c8]>,
    >            'featureType': 'Simple',
    >            'fields': [<Field object at 0x30744cc0[0x35836490]>,
    >                       <Field object at 0x30744c88[0x35836850]>,
    >                       <Field object at 0x307445c0[0x35836890]>,
    >                       <Field object at 0x30744c50[0x358368d0]>,
    >                       <Field object at 0x30744940[0x35836910]>,
    >                       <Field object at 0x307445f8[0x35836830]>,
    >                       <Field object at 0x30744630[0x35836970]>,
    >                       <Field object at 0x30744710[0x358369b0]>],
    >            'file': 'pipe',
    >            'fullPropsRetrieved': True,
    >            'geometryStorage': '',
    >            'globalIDFieldName': '',
    >            'hasGlobalID': False,
    >            'hasM': False,
    >            'hasOID': True,
    >            'hasSpatialIndex': True,
    >            'hasZ': False,
    >            'indexes': [<Index object at 0x30744780[0x358369f0]>,
    >                        <Index object at 0x307447b8[0x35836a50]>],
    >            'isCOGOEnabled': False,
    >            'isTimeInUTC': True,
    >            'isVersioned': False,
    >            'lengthFieldName': 'Shape_Length',
    >            'metadataRetrieved': False,
    >            'modelName': '',
    >            'name': 'pipe',
    >            'path': 'G:\\project\\capacity\\capacity\\capacity.gdb',
    >            'rasterFieldName': '',
    >            'relationshipClassNames': [],
    >            'representations': [],
    >            'shapeFieldName': 'Shape',
    >            'shapeType': 'Polyline',
    >            'spatialReference': <SpatialReference object at 0x30744e48[0x35836a90]>,
    >            'subtypeFieldName': '',
    >            'versionedView': ''},  'timeValueFormat': '',  'versionedView': '',  'whereClause': ''}
5

You probably just have to brute force it and create a list of all possible describe object properties.

inOb = r"C:\Your\Input"
desc = arcpy.Describe (inOb)
properties = ['DSID', 'FIDSet', 'GCSTransforms', 'JPEGQuality',
          'LERCTolerance', 'MExtent', 'OIDFieldName', 'ZClusterTolerance',
          'ZExtent', 'ZFactor', 'accumulators', 'aliasName',
          'allowedCompressionMethods', 'allowedFields',
          'allowedMensurationCapabilities', 'allowedMosaicMethods',
          'alternateName', 'applyColorCorrection', 'areaFieldName',
          'areaOfInterest', 'associationSource', 'attributes',
          'backwardPathLabel', 'bandCount', 'baseName', 'batch',
          'blendWidth', 'blendWidthUnits', 'canVersion', 'cardinality',
          'catalogPath', 'categories', 'cellSizeToleranceFactor',
          'changeTracked', 'checkParameters', 'children',
          'childrenExpanded', 'childrenNames', 'classKey',
          'clipToBoundary', 'clipToFootprint', 'clusterTolerance',
          'compressionType', 'connectionProperties', 'connectionString',
          'connectionsFeatureClass', 'constraintCount',
          'createDirtyAreaForAnyAttributeUpdate', 'createdAtFieldName',
          'creationTime', 'creatorFieldName', 'currentRelease',
          'dataCollection', 'dataElement', 'dataElementType',
          'dataType', 'datasetType', 'defaultCompressionMethod',
          'defaultMensurationCapability', 'defaultMosaicMethod',
          'defaultProcessingTemplate', 'defaultResamplingMethod',
          'defaultSubtypeCode', 'defaultTravelModeName', 'description',
          'destinationClassKeys', 'destinationClassNames',
          'diagramClassName', 'dimensionAttributes', 'dimensionNames',
          'dimensionValues', 'directions', 'domainNetworks', 'domains',
          'edgeSources', 'editedAtFieldName', 'editorFieldName',
          'editorTrackingEnabled', 'elevationModel', 'endTimeField',
          'errorMessage', 'errorNumber', 'evaluationOrder',
          'excludeFromClientEvaluation', 'excludeRestrictedElements',
          'extension', 'extensionProperties', 'extent', 'featureClass',
          'featureClassNames', 'featureClassType', 'featureType',
          'fieldInfo', 'fieldName', 'fieldNames', 'fields', 'file',
          'fileCount', 'findClosest', 'footprintMayContainNoData',
          'format', 'forwardPathLabel', 'fullPropsRetrieved',
          'geometryStorage', 'globalID', 'globalIDFieldName',
          'hasEdgeTagValues', 'hasFAT', 'hasGlobalID', 'hasM',
          'hasNodeTagValues', 'hasOID', 'hasSpatialIndex',
          'hasStatistics', 'hasTriangleTagValues', 'hasZ', 'height',
          'hierarchyAttribute', 'hierarchyLevelCount',
          'historicalTrafficData', 'id', 'ignoreInvalidLocations',
          'impedance', 'indexes', 'is2D', 'is3D', 'isArchived',
          'isAttachmentRelationship', 'isAttributed', 'isAutoCAD',
          'isBuildable', 'isComposite', 'isDGN', 'isDelaunay',
          'isEditingRestrictive', 'isEnabled', 'isIndexed', 'isInteger',
          'isMultidimensional', 'isPseudo', 'isRedefined', 'isReflexive',
          'isTimeInUTC', 'isVersioned', 'itemSet', 'itemType', 'json',
          'junctionSources', 'keyType', 'layer', 'lengthFieldName',
          'liveTrafficData', 'locatorCount', 'locators',
          'maxDownloadImageCount', 'maxDownloadSizeLimit',
          'maxRastersPerMosaic', 'maxRecordsReturned', 'maxRequestSizeX',
          'maxRequestSizeY', 'maxValueForHierarchyX',
          'maximumGeneratedErrorCount', 'meanCellHeight',
          'meanCellWidth', 'metadataRetrieved', 'minimalDirtyAreaSize',
          'minimumPixelContribution', 'modelName', 'mosaicOperator',
          'multidimensionalInfo', 'name', 'nameString',
          'needsUpdateStatistics', 'network', 'networkAttributes',
          'networkType', 'noDataValue', 'notification', 'numberDecimals',
          'optimizations', 'orderBaseValue', 'orderField',
          'originClassKeys', 'originClassNames',
          'orphanJunctionFeatureClassName', 'outputWidth',
          'overrideFieldName', 'parameterCount', 'parameters',
          'parcelTypeNames', 'parcelTypes', 'path', 'permanent',
          'pixelType', 'pjson', 'pointCount', 'pointsFeatureClass',
          'primaryField', 'proVersion', 'processingTemplates',
          'rasterFieldName', 'rasterMetadataLevel', 'recordsFeatureClass',
          'referenced', 'referencesExternalService',
          'relationshipClassNames', 'relationshipRules', 'release',
          'representations', 'requireShapeOverride',
          'requiredGeodatabaseClientVersion', 'restrictions',
          'ruleIDFieldName', 'schemaGeneration', 'scriptExpression',
          'searchTolerance', 'sensorType',
          'serviceTerritoryFeatureClassName', 'severity',
          'shapeFieldName', 'shapeType', 'solverName', 'solverProperties',
          'sortAscending', 'sources', 'spatialReference', 'startPosition',
          'startTimeField', 'subtypeCode', 'subtypeFieldName',
          'supportsDirections', 'supportsHistoricalTrafficData',
          'supportsLiveTrafficData', 'supportsTurns',
          'systemJunctionSource', 'table', 'tableType', 'tags',
          'terminalConfigurations', 'timeValueFormat',
          'timeZoneAttributeName', 'timeZoneTableName', 'topology',
          'topologyEnabled', 'trafficSupportType', 'triggeringEvents',
          'turnSources', 'type', 'uTurns', 'useHierarchy', 'useTime',
          'userEditable', 'usesRelativePath', 'variableAttributes',
          'variableNames', 'versionedView', 'viewpointSpacingX',
          'viewpointSpacingY', 'whereClause', 'width',
          'workspaceFactoryProgID', 'workspaceType']
for prop in properties:
     try: print "{}:\t{}".format (prop, getattr (desc, prop))
     except AttributeError: continue

Results:

DSID:   304
backwardPathLabel:  Main
baseName:   Main
canVersion: True
cardinality:    OneToMany
...
1
  • Yes. Embrace the insanity. Commented May 24, 2023 at 15:57

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .