i have done this:
import os
import fiona
rootdir = r'C:\Users\user\Desktop\a' # path to your root directory you walk
sfiles = {} # a dictionary with all the .shp files
for entry in os.listdir(rootdir):
dirpath = os.path.join(rootdir, entry)
if os.path.isdir(dirpath):
for file in os.listdir(dirpath): # Get all files in the subdirectories
if file.endswith('.shp'): # If it's an .shp.
filepath = os.path.join(dirpath, file)
sfiles[filepath[:-4]] = fiona.open(filepath)
then you make an action dict like this:
action_dict = {'INT': 'intersection', 'ER': 'difference'}
and later
action, shape1, shape2 = line.split('_') # here line is ER_ASTOM_ASTIK or whatever line in your txt file
if shape1 in sfiles and shape2 in sfiles:
gpd.overlay(sfiles[shape1], sfiles[shape2], how=action_dict[action])
THE LAST VERSION