Skip to main content

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

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.

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!

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

forestiler-0.2.2a1.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

forestiler-0.2.2a1-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file forestiler-0.2.2a1.tar.gz.

File metadata

  • Download URL: forestiler-0.2.2a1.tar.gz
  • Upload date:
  • Size: 13.1 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

Hashes for forestiler-0.2.2a1.tar.gz
Algorithm Hash digest
SHA256 9a14ccd389e4f49b874f91749df99b85249cab56570835329d482dbaa70f80d1
MD5 1adb9d371c8e70aaad685c402d7b28ae
BLAKE2b-256 37619dd1ec44c3b85cf1ddfc25bb7244ec99e9026490294bdcef8a3385401c06

See more details on using hashes here.

File details

Details for the file forestiler-0.2.2a1-py3-none-any.whl.

File metadata

  • Download URL: forestiler-0.2.2a1-py3-none-any.whl
  • Upload date:
  • Size: 14.8 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

Hashes for forestiler-0.2.2a1-py3-none-any.whl
Algorithm Hash digest
SHA256 c68c36fb9a77c644e2c320752dd31118caf4a69679203203a651e696e42cf6b2
MD5 229232a78f45958830ec816ef3be73ec
BLAKE2b-256 4b96d9d896db89ff5ebf43192a65ee0dc3e849da622fd28b51ca1d5fc4109e95

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page