diff --git a/notebooks/make_virtual_raster.ipynb b/notebooks/make_virtual_raster.ipynb new file mode 100644 index 0000000..2ebdd52 --- /dev/null +++ b/notebooks/make_virtual_raster.ipynb @@ -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 +}