-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple snippet for building one mosaic from multiple transect-rasters
- Loading branch information
1 parent
1c4ec4c
commit bdd7094
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'D:\\\\Specim\\\\Missions\\\\2022-08-31-Remoy\\\\remoy_202208311040_ntnu_hyperspectral_74m\\\\processed\\\\Output\\\\GIS\\\\RGBComposites\\\\combined.tif'" | ||
] | ||
}, | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"import os\n", | ||
"from rasterio import open\n", | ||
"from osgeo import gdal\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
"def merge_rasters(raster_file_list, output_file, width=None, height=None): ## Adding width and height as custom parameters if want to change the size of raster\n", | ||
" \n", | ||
" ds_lst = list()\n", | ||
" for raster in raster_file_list:\n", | ||
" ds = gdal.Warp('', raster, format='vrt')\n", | ||
" ds_lst.append(ds)\n", | ||
" dataset = gdal.BuildVRT('', ds_lst)\n", | ||
" ds1 = gdal.Translate(output_file, dataset)\n", | ||
" del ds1 \n", | ||
" del dataset\n", | ||
" return output_file\n", | ||
"\n", | ||
"# Example usage\n", | ||
"input_folder = r\"D:\\Specim\\Missions\\2022-08-31-Remoy\\remoy_202208311040_ntnu_hyperspectral_74m\\processed\\Output\\GIS\\RGBComposites\"\n", | ||
"\n", | ||
"import glob\n", | ||
"all_raster_files = glob.glob(input_folder+'/*.tif')\n", | ||
"output_filename = os.path.join(input_folder,\"combined.tif\")\n", | ||
"\n", | ||
"\n", | ||
"merge_rasters(all_raster_files, output_filename)\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.18" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |