Skip to main content

ForesTiler — Create Image Tiles From Large Input Rasters According to a Classified Mask Vector File

DOI

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.

Metadata

Release files for forestiler 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for forestiler 0.2.2
File Size Uploaded
forestiler-0.2.2.tar.gz 13.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for forestiler 0.2.2
File Interpreter ABI Platform
forestiler-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 28.8 kB

Release files / forestiler-0.2.2.tar.gz

Download URL forestiler-0.2.2.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c735817b5863e8aa136e4a47d9905c3fe08931a2e201aec48ceb135861ba0cc0
BLAKE2b-256 checksum
How to use checksums
a1d7f917f2e8083cf94790b47b3018c26dfcf2ac11e479d1d2297b3944b2c715
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.8.10 Linux/5.4.0-152-generic

Release files / forestiler-0.2.2-py3-none-any.whl

Download URL forestiler-0.2.2-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad24c8d5bcbe1f8f40a807511d0de4f0590ee890f60c335ab990e68e1bced0f5
BLAKE2b-256 checksum
How to use checksums
e36c733e887158a47d2d2047a33980b02a26940f4a78febfbda6f4f51f877a4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.8.10 Linux/5.4.0-152-generic
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page