Monday, 22 October 2018

Using Python to execute merge of rasters


I need help with a python script to iterate merge (gdal_merge.py) of rasters:


For each folder located in /home/geodata/sentinel2/ look in subfolder IMG_DATA and merge the three rasters with filenames ending with B08.jp2, B04.jp2 and B03.jp2 to output /home/geodata/outputfolder/raster1.tif



and then move to the next folder in /home/geodata/sentinel2/ and do the same thing and output raster2.tif to the same output folder as raster1


and so on... enter image description here



Answer



rather than giving you a full answer I want to give you some tools:


from os import listdir 

(https://stackoverflow.com/questions/5817209/browse-files-and-subfolders-in-python)


will give you files, folders. Take a look at .basename and .extenhsion. You can use regular expressions to filter the files you need as an alternative to exact matches.


think you can find all sub questions in other topics.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...