TransWikia.com

List datasets from geodatabase faster

Geographic Information Systems Asked by gacero on March 1, 2021

I’m using a script to list datasets from multiple gdbs in ArcPy (to rename most datasets and gdbs). Which looks like this:

dir_gdbs = 'D:mypath'
os.chdir(dir_gdbs)

lista_gdbs = glob.glob('*.gdb')
for i in lista_gdbs:
    gdb = (os.path.join(dir_gdbs,i))
    arcpy.env.workspace = gdb
    lista_capas = arcpy.ListDatasets()
    for u in lista_capas:
        #do stuff

It works correctly but there are many gdbs to process and it is very slow. Most of its time is lost changing the workspace (arcpy.env.workspace = gdb). Is there any way to list the datasets within each gdb without doing this?

One Answer

I finally used arcpy.da.walk() as PolyGeo suggested.

walk = arcpy.da.Walk(dir_gdbs)
for gdb, x, capas in walk:
    for capa in capas:
        dir, gdb = os.path.split(gdb)
        #do stuff 

Correct answer by gacero on March 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP