Identify datastore of a layer in arcpy

345
2
11-08-2023 03:13 AM
TonyO
by
New Contributor III

Hi,

In ArcGIS Pro's SDK we can access the datastore of layer's table. And then we can check the type of datastore. So basically I have to check whether the layer was created from sql database, file database or using plugin data source. In SDK we can access the data store and then check whether it is of type Geodatabase, FileSystemDatastore or PluginDatastore

Do we anything like this in arcpy? Or is there any other way to check this?

0 Kudos
2 Replies
MobiusSnake
MVP

I think it's possible with Pro 3.2, but wasn't before.

It looks like an arcpy.Describe() call on a dataset will include a "workspace" property, which will give you a Describe() result for the data source.  From there you can use the workspaceFactoryProgID to get what I believe are the old ArcObjects COM ProgIDs for the workspace factories, e.g. "esriDataSourcesGDB.FileGDBWorkspaceFactory.1".

0 Kudos
StaticK
MVP

I think you could get those items from the layer properties and looking at the layer.datasource property.

aprx = arcpy.mp.ArcGISProject()
for m in arcpy.listMaps('Map2'):
    for lyr in m.listLayers():
        datasource = lyr.dataSource
        srv_details = re.compile(r'(?<=Database Platform=)(.*),U')
        if srv_details.search(datasource).group(1):
            datastsore = srv_details.search(datasource).group(1)
            print(datastore)
                
    

 

0 Kudos