TransWikia.com

Is there any fast looping through too many shapefiles in a folder using ArcPy?

Geographic Information Systems Asked by Anahita Kp on December 7, 2020

Looping through shapefile using arcpy.ListFeatureClasses() is very slow for many shapefiles. because first thing first, it writes all in memory as a list and then read each shapefile one by one.
Is there any other way to read one by one shapefile without making them as a list and write it in the memory:

This is the slow script:

arcpy.env.workspace = shapefile_folder
fc_list = arcpy.ListFeatureClasses()
for shapefile in fc_list:
     print (fc) # doing the processing over shp here

One Answer

You can get a very quick list of the shapefiles in a folder with a command like filter(lambda x: x.lower().endswith('.shp'), os.listdir(<dir>)). As some of the comments imply, this will not test to ensure that all of the results refer to complete & readable shapefiles though.

Answered by Bjorn on December 7, 2020

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