Skip to main content
Question

Data sources in an ArcGIS project (aprx)


creinier
Contributor
Forum|alt.badge.img+3

I’m working on a data inventory project and need to figure out what data sources are being used in a large number of aprx’s. Is there a way to determine the data sources of an ArcGIS project by directing a workbench to an aprx file path?

3 replies

hkingsbury
Celebrity
Forum|alt.badge.img+53
  • Celebrity
  • April 10, 2025

Sorry, a very brief reply, but i’ll come back later and expand if needed.

You can use ArcPy in a PythonCaller to list the layers in an APRX

 

https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/updatingandfixingdatasources.htm

https://chatgpt.com/share/67f84756-d79c-8005-ac73-b522691aa5b5


koala_pond_03
Participant
Forum|alt.badge.img+1

Hey, I’ve made a python script for a similar project at work. I hope this helps.

import csv, arcpy, datetime, time
aprx = arcpy.mp.ArcGISProject(r'\\network\folder\project.aprx')
maps = aprx.listMaps()
for map in maps:
    layers = map.listLayers()

out_path = r'\\network\folder'
ts = datetime.datetime.fromtimestamp(time.time()).strftime('%Y%m%d_%H%M%S')
csv_file = out_path + r'\aprx_report_' + ts + '.csv'
print(csv_file)
output = ''
output = 'Layer,Group_Layer,Feature_Class,Server\n'

def listLayers():
    results = ''
    temp = ''
    featureLayer = layer.longName.split('\\')
    if len(featureLayer) > 0:
        try:
            datasource = layer.dataSource
            datasourceProperties = datasource.split(',')
            d = dict(s.split('=') for s in datasourceProperties)
            groupLayer = featureLayer
            del groupLayer[-1]
            groupLayer = ' >> '.join(groupLayer)
            temp = (str(layer.name) + ',' + groupLayer + ',' + d.get('Dataset') + ',' + d.get('Server'))
            results = results + temp + '\n'
        except:
            print('failed: ')
            print(featureLayer)
    if len(featureLayer) == 0:
        try:
            datasource = layer.dataSource
            datasourceProperties = datasource.split(',')
            d = dict(s.split('=') for s in datasourceProperties)
            temp = (str(layer.name) + ',,' + d.get('Dataset') + ',' + d.get('Server'))
            results = results + temp + '\n'
        except:
            print('failed: ')
            print(featureLayer)
    return results

def listRasters():
    results = ''
    temp = ''
    featureLayer = layer.longName.split('\\')
    if len(featureLayer) > 0:
        try:
            datasource = layer.dataSource
            ## print(datasource)
            datasourceProperties = datasource.split(',')
            if len(datasourceProperties) > 1 :
                groupLayer = featureLayer
                del groupLayer[-1]
                d = dict(s.split('=') for s in datasourceProperties)
                temp = (str(layer.name) + ',' + ''.join(groupLayer) + ',' + d.get('Dataset') + ',' + d.get('Server'))
                results = results + temp + '\n'                
            if len(datasourceProperties) == 1:
                temp = (str(layer.name) + ',,' + ''.join(datasourceProperties) + ',')
                results = results + temp + '\n'
            else:
                pass
        except:
            print('failed: ')
            print(featureLayer)
    if len(featureLayer) == 0:
        try:
            pass
            # datasource = layer.dataSource
            # datasourceProperties = datasource.split(',')
            # d = dict(s.split('=') for s in datasourceProperties)
            # temp = (str(layer.name) + ',,,')
            # results = results + temp + '\n'
        except:
            print('failed: ')
            print(featureLayer)
    return results

for layer in layers:
    if layer.isGroupLayer == True:
        pass
    elif layer.isRasterLayer == True:
        output = output + listRasters()
    elif layer.is3DLayer == True:
        output = output + listLayers()
    elif layer.isFeatureLayer == True:
        output = output + listLayers()
    else:
        pass

print(output)
file = open(csv_file, 'w')
file.write(output)
file.close()
print('done')

 


creinier
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • April 11, 2025

Thanks ​@hkingsbury and ​@koala_pond_03 for the suggestions and examples! I’ll give that a shot!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings