Create Image Tiles From Large Input Rasters According to a Classified Mask Vector File
Project description
ForesTiler — Create Image Tiles From Large Input Rasters According to a Classified Mask Vector File
ForesTiler provides a CLI tool to create image tiles from large input rasters according to a classified mask vector file. The goal is to export images that are completely covered by a class polygon. They can be saved either as PNGs to directly feed them into machine learning frameworks which may not interop with geodata or as GeoTIFFs when retention of geographic information is deemed important.
[!IMPORTANT] It was decided to trade computational efficiency and versatility for somewhat cleaner code. Thus, you may need to reduce the size of your input images. Also, also, this means only square images are supported
Installation
[!WARNING] Please note, that you need to have at least Python 3.9 installed.
[!TIP] Use pipx instead of pip which also creates a unique virtual environment for environment isolation.
You can install forestiler
via pip by running
pip install forestiler
Usage
[!CAUTION] Only north-up images are supported. If your raster images are rotated, please transform them first!
[!CAUTION] Don't quote class labels on the command line.
usage: forestile [-h] [--no-progress] [--pad] [--kernel-size KERNEL_SIZE] [--stride STRIDE]
--vector-mask VECTOR_MASK [--class-field CLASS_FIELD] [--all-classes]
[--classes CLASSES [CLASSES ...]] [--input-glob INPUT_GLOB] [--geo-tiff]
input out
forestile creates image tiles from large input rasters according to a classified mask vector file.
positional arguments:
input Directory containing raster files to tile.
out Directory where output files should be stored.
May not exist prior to program invocation.
optional arguments:
-h, --help show this help message and exit
--no-progress Disable progress bar
--pad Disable padding of input images.
--kernel-size KERNEL_SIZE
Kernel size in pixels.
--stride STRIDE Stride of kernel.
--vector-mask VECTOR_MASK
Path to vector file. Always reads first layer,
if driver supports multi-layerr files (e.g. Geopackages).
--class-field CLASS_FIELD
Attribute field containing class values.
--all-classes Generate image chips for all unique values in class field.
--classes CLASSES [CLASSES ...]
List of classes to build image tiles for.
--input-glob INPUT_GLOB
Optional glob pattern to filter files in input directory.
--geo-tiff Store image chips as GeoTiffs instead of PNGs.
Copyright: Florian Katerndahl <florian@katerndahl.com>
Example Usage
Given a directory structure like the one listed below, the following command reads the file mask.gpkg
and queries all geometries where the attribute "tree" matches "oak".
All output image chips, here as georeferenced TIFF files, are written into the directory output
(which may not exist prior to program invocation).
forestile --stride 50 --vector-mask mask.gpkg --class-field tree --classes "oak" --geo-tiff rasters/ output/
.
├── output/
├── rasters/
│ ├── truedop20rgb_386_5808_2_be_2020.tif
│ ├── truedop20rgb_386_5810_2_be_2020.tif
│ ├── truedop20rgb_388_5808_2_be_2020.tif
│ └── truedop20rgb_388_5810_2_be_2020.tif
└── mask.gpkg
Contribution
Bug reports, suggestions and feature requests are always welcomed. Please open an issue on GitHub.
Citation
If you use this package, see CITATION and cite this work.
Acknowledgements
This package was developed at the Remote Sensing Lab at Freie Universität Berlin.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file forestiler-0.2.2.tar.gz
.
File metadata
- Download URL: forestiler-0.2.2.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.8.10 Linux/5.4.0-152-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c735817b5863e8aa136e4a47d9905c3fe08931a2e201aec48ceb135861ba0cc0 |
|
MD5 | e60986e9a65e20e3e8fbe7f1618ff0ad |
|
BLAKE2b-256 | a1d7f917f2e8083cf94790b47b3018c26dfcf2ac11e479d1d2297b3944b2c715 |
File details
Details for the file forestiler-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: forestiler-0.2.2-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.8.10 Linux/5.4.0-152-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad24c8d5bcbe1f8f40a807511d0de4f0590ee890f60c335ab990e68e1bced0f5 |
|
MD5 | 241624ea69f74c8629dc2cbf4ae2eab8 |
|
BLAKE2b-256 | e36c733e887158a47d2d2047a33980b02a26940f4a78febfbda6f4f51f877a4c |