0

How to get distinct data sources of layers and tables in ArcGIS Pro project?

    aprx = arcpy.mp.ArcGISProject("CURRENT")
    maps = aprx.listMaps()
    for map in maps:
        print ('--------------------------------------------------------------')
        print (map.name)
        print ('--------------------------------------------------------------')
        layers = map.listLayers()
        tables = map.listTables()
        for layer in layers:
          print (layer.dataSource)
        for table in tables:
          print (table.dataSource)
4
  • 2
    Try creating a list of all of them, then use a set to remove duplicates - see stackoverflow.com/questions/7961363/…
    – PolyGeo
    Commented Feb 7, 2023 at 11:20
  • 1
    This isn't an ArcGIS Pro question, or even a GIS question, it is a basic Python programming question, and a quick search for finding unique values in a list yields numerous answers. The ArcGIS Pro aspect of this question is already answered How to get a list of all data sources used in a ArcGIS Pro project? - GIS SE
    – bixb0012
    Commented Feb 7, 2023 at 13:35
  • I'm newby to Python, so I can't figure it out by myself. Tried to use set, but it didn't worked in ArcPy, so maybe it's not generel Python question, but ArcPy's.
    – Fikusas
    Commented Feb 7, 2023 at 14:39
  • Please don’t ask follow up questions in the same question. Ask a new question and link to the original as context, if it’s relevant.
    – PolyGeo
    Commented Feb 10, 2023 at 10:18

1 Answer 1

1

List layer objects, extract their sources using dataSource property, convert to a set which can't have duplicates:

import arcpy

aprx = arcpy.mp.ArcGISProject("CURRENT")

layers = [] #A list to hold layer objects

for mp in aprx.listMaps(): #For each map in the project
    for layer in mp.listLayers(): #Find all layers
        layers.append(layer)
    for table in mp.listTables(): #And tables
        layers.append(table)
        
sources = [x.dataSource for x in layers] #Extract their sources
print(set(sources)) #Print unique sources

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.