-
Roelofsen, Hans authoredRoelofsen, Hans authored
COMBINE
Description
The WENR Combine tool combines two or more categorical geospatial rasters. It creates a new geospatial integer raster in which each value points to a unique combination of categories of the input rasters. The key to the unique combinations is provided in a *.csv table.
This is an open source adaptation of the ArcGIS Pro Combine Tool.
The illustration below demonstrates the Combine tool.
Left and center are two integer arrays, called 'beheertypen' and 'top10'. These are the two input rasters. The Combine tool output is shown on the right. It is an array of euqal dimensions. The values in it point to specific combinations of 'beheertypen' and 'top10'. The associated table would look like:
| value | beheertypen | top10 |
|---|---|---|
| 1 | 10 | 160 |
| 2 | 10 | 100 |
| 3 | 10 | 143 |
| 4 | 11 | 142 |
| 5 | 11 | 143 |
| 6 | 11 | 144 |
| 7 | 11 | 100 |
| 8 | 12 | 161 |
| 9 | 13 | 144 |
The combine tool is designed for use in conjunction with the Multi-Reclass Tool.
Installation
The Combine tool requires a Python environment with the following modules installed:
- numpy
- pandas
- rasterio
- prefect 1.0
Usage
Use the Command Line Interface to handle the Combine tool. Positional arguments are:
positional arguments:
destination path to destination *.tif file
sources path to destination source files
options:
-h, --help show this help message and exit
--test test run with 20 windows
For example, the following input takes 2 input rasters:
python COMBINE.py c:/apps/test_combine/combinations01.tif c:/apps/test_data/top10.tif c:/apps/test_data/beheertypen.tif
The output would be:
c:\apps\test_combine\combinations01.tif <<-- the Geospatial raster
c:\apps\test_combine\combinations01.csv <<-- CSV file with key to the output TIFF
For testing purposes, add --test to the Command Line command. This restricts the tool to only 20 sub-windows.
Users within the WUR network can use the following commands for testing purposes.
Testing run: python COMBINE.py <output_location>.tif w:\PROJECTS\DUIN\Data\NATUUR\BasisbestandNatuurLandschap\BNL2020\Bedrijventerrein_Pos5_20210315time162111.tif w:\PROJECTS\DUIN\Data\NATUUR\BasisbestandNatuurLandschap\BNL2020\OAD_Bebkom_Top10_Vlak_2020_sept_Pos4_20210302time141928.tif w:\PROJECTS\DUIN\Data\NATUUR\BasisbestandNatuurLandschap\BNL2020\Top10_Vlak_2020_sept_Pos1_20210325time161731.tif --test
Full run: python COMBINE.py <output_location>.tif w:\PROJECTS\DUIN\Data\NATUUR\BasisbestandNatuurLandschap\BNL2020\Bedrijventerrein_Pos5_20210315time162111.tif w:\PROJECTS\DUIN\Data\NATUUR\BasisbestandNatuurLandschap\BNL2020\OAD_Bebkom_Top10_Vlak_2020_sept_Pos4_20210302time141928.tif w:\PROJECTS\DUIN\Data\NATUUR\BasisbestandNatuurLandschap\BNL2020\Top10_Vlak_2020_sept_Pos1_20210325time161731.tif
Details
The Combine tool verifies that all input rasters have an identical extent and resolution, and quits if this is not the case.
The Combine tool subdivides the geographical extent of the input rasters into many windows, which are processed in parallel. The default window size is 2.000 X 2.000 pixels. The tool assumes that the input raster width and height are conmensurable with the window size. This is assumed but not verified.
The Combine tool writes temporary files to disk. Around ~60GB local storage capacity is required.
Run time for combining 7 rasters with shape 112.000 X 130.000 on a 16GB RAM laptop is 5.5 hours.
Support
Get in touch with Hans.
Authors and acknowledgment
Thanks to Johan B: https://stackoverflow.com/a/59962140/981768
License
CC BY-NC-SA 4.0