I'm new to Python.
I have two dataset folders one with subfolders containing shapefiles and the other with subfolders containing raster. I'm trying to complete a loop that takes the polygons of the first subfolder that have in common the same attribute e.g. 'class' and uses them to make a clip on the first raster subfolder, repeating the loop for the second folder ec.., saving all the results in a new folder with the subfolders of its new cut raster. I tried using gdal but the output only returns the list of files ending with '.tiff'.
How can I fix it?
import os, fnmatch
import geopandas as gpd
import gdal
Workspace = 'F://...//rasters'
S2_path = os.path.join (Workspace)
for subdir, dirs, files in os.walk(S2_path):
for file in files:
filepath = subdir + os.sep + file
if filepath.endswith(".tif"):
print (filepath)
OutputFolder = 'F://...//output/'
for polygon in polygons:
gdf=gpd.read_file('F://...//shapefile.shp')
df1 = gdf[['class','geometry']]
options = gdal.WarpOptions(cutlineDSName=df1,cropToCutline=True)
outRaster = gdal.Warp(srcDSOrSrcDSTab=filepath,
destNameOrDestDS=OutputFolder + '_crop',
options=options)
outRaster= None