Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/cog overviews #90

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions cloud-optimized-geotiffs/cogs-overview_resampling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
"source": [
"# Cloud Optimized Geotiff (COG) Overview Resampling\n",
"\n",
"When making Cloud-Optimized GeoTIFFs (COGs) you can select the resampling method used to generate the overviews. Different types of data can drastically change appearance when more zoomed out based on the method selected. This is most important when using software that renders from overviews (e.g QGIS, ArcGIS), particularly web tilers like Titiler. \n",
"When making Cloud-Optimized GeoTIFFs (COGs) you can select the resampling method used to generate the overviews. Different types of data can drastically change appearance when more zoomed out based on the method selected. This is most important when using software that renders from overviews (e.g QGIS, ArcGIS), particularly web tilers like [Titiler](https://developmentseed.org/titiler/). \n",
"\n",
"Also when using a tiling service on high resolution dataset you will often have many tiles of source data. The idea behind this notebook, is that before you generate all your final output data, as COGs, or if you need to rebuild your overviews, you should first test on some representative samples. After testing you'll then know which method to use in your data pipeline.\n",
"\n",
"This notebook loops over the overview resampling methods available in gdal applying it to the same sample tile so that we can compare how the dataset will appear when zoomed out from the full resolution. \n",
"This notebook loops over the overview resampling methods available in [GDAL](https://gdal.org/) applying it to the same sample tile so that we can compare how the dataset will appear when zoomed out from the full resolution. \n",
"\n",
"> Note: GDAL 3.2 added the ability to specify the resampling method for the overviews specifically. GDAL 3.3 added a couple of new resampling methods. \n",
"\n",
"## Setup Environment\n",
"\n",
"* Requires gdal >= 3.2 for Overview Resampling to work\n",
"* Requires `gdal >= 3.2` for Overview Resampling to work\n",
"* RMS resampling was added in GDAL 3.3\n",
"\n",
"\n",
Expand Down Expand Up @@ -287,7 +287,7 @@
}
],
"source": [
"# The original file does not contain overviews\n",
"# Using rio cogeo we can investigate if the file has tiles and what resampling was used.\n",
"\n",
"!rio cogeo info {tile}"
]
Expand Down Expand Up @@ -343,28 +343,43 @@
" return dst_path"
]
},
{
"cell_type": "markdown",
"id": "8577e1d8",
"metadata": {},
"source": [
"Now lets make a list of the Resampling methods offered by GDAL. Some resampling methods aren't appropriate for the data, so we are doing to drop those from the list. You can see descriptions at https://gdal.org/programs/gdalwarp.html#cmdoption-gdalwarp-r "
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 1,
"id": "67cb709e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['nearest', 'bilinear', 'cubic', 'cubic_spline', 'lanczos', 'average', 'mode', 'gauss', 'rms']\n"
"['nearest', 'bilinear', 'cubic', 'cubic_spline', 'lanczos', 'average', 'mode', 'gauss', 'sum', 'rms']\n"
]
}
],
"source": [
"# Make a list of resampling methods that GDAL 3.4+ allows\n",
"\n",
"from rasterio.enums import Resampling as ResamplingEnums\n",
"from rasterio.enums import Resampling\n",
"\n",
"# Drop some irrelevant methods\n",
"OverviewResampling = [r for r in ResamplingEnums if (r.value < 8) or r.value > 13]\n",
"resample_methods = [r.name for r in OverviewResampling]\n",
"excluded_resamplings = {\n",
" Resampling.max,\n",
" Resampling.min,\n",
" Resampling.med,\n",
" Resampling.q1,\n",
" Resampling.q3,\n",
"}\n",
"OverviewResampling = [method for method in Resampling if method not in excluded_resamplings]\n",
wildintellect marked this conversation as resolved.
Show resolved Hide resolved
"resample_methods = [method.name for method in OverviewResampling]\n",
"print(resample_methods)"
]
},
Expand Down
Loading