2

I have a huge amount of Raster Layers and I only want to change the cell size using gdal warpreproject. This is my attempt:


import os.path, glob

inputpath = 'C:/Users/DGM1'
outputpath = 'C:/Users/output'

directory = os.fsencode(inputpath)
os.chdir(inputpath)

for file in glob.glob('*.txt'):
    print(file)
    filename = os.fsdecode(file)
    inputname = os.path.join(os.fsdecode(directory), filename)
    outputname = outputpath + "warped" + str(filename)
    processing.run("gdal:warpreproject", 
        {'INPUT':inputname, 'SOURCE_CRS':None,
         'TARGET_CRS':QgsCoordinateReferenceSystem('EPSG:25832'),
         'RESAMPLING':0, 'NODATA':None, 'TARGET_RESOLUTION':5, 'OPTIONS':'',
         'DATA_TYPE':0, 'TARGET_EXTENT':None, 'TARGET_EXTENT_CRS':None,
         'MULTITHREADING':False, 'EXTRA':'', 'OUTPUT':outputname})

I don't get any mistake when running the code but there are no raster layers saved to the output.

Any idea what could be the mistake?

1 Answer 1

4

You need to change output file extension. I guess GDAL doesn't support .txt extension. Use for example .XYZ. You also miss / or \\ (path separator).

Change

outputname = outputpath + "warped" + str(filename)

to

outputname = os.path.join(outputpath, "warped" + str(filename)[:-3] + 'XYZ')
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.