1

Based on answered script from a previous question I continued studying GeoPackage documentation but I didn't found a solution to overwrite the table in GeoPackage when the original file (in 'rasterfolder') has changes. In this case, append works when I run the script for the first time, however, if there is a change in the original file, it does not update when I run the script again (maybe skips update if has same table name). I would like it to be updated according to the source file in 'rasterfolder'.

import os

newgpkg = '/home/user/Desktop/all_rasters.gpkg' #Will be created if it doesnt exist
rasterfolder = r'/home/user/Desktop/GIS/Data/testdata/' #All tif rasters in this folder and all subfolders will be converted

for root, folder, files in os.walk(rasterfolder):
    for file in files:
        if file.endswith('.tif'): #For each tif file in rasterfolder
        print('Processing {0}'.format(file))
        fullname = os.path.join(root, file)
        newname = file.replace('.tif', '_trans') #Adjust this line to change how the output rasters are named
        processing.run("gdal:translate", {'INPUT':fullname,'TARGET_CRS':None,'NODATA':None,
        'COPY_SUBDATASETS':False,'OPTIONS':'APPEND_SUBDATASET=YES|RASTER_TABLE={0}'.format(newname),
        'EXTRA':'','DATA_TYPE':0,'OUTPUT':newgpkg})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.