qgis / QGIS-Processing

Example scripts, algorithms etc
98 stars 86 forks source link

Applying function to all files in directory using PyQGIS/Python? #87

Open vincent-26 opened 5 years ago

vincent-26 commented 5 years ago

Hello everyone how can I apply this function to all files in folder? The function in question extracts the bands from a raster file (.ecw) and I would like to be able to do it to all the files in folder. What should I do?

import gdal

in_path = "C:/gis_data/ECW"
out_path ="C:/gis_data/output"

src_ds = gdal.Open(in_path)

for i in range(1,src_ds.RasterCount+1):
    out_ds = gdal.Translate(out_path + 'test' + str(i) + '.ecw', src_ds, format='GTiff', bandList=[i])
    out_ds=None