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.2a0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: forestiler-0.2.2a0.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.2a0.tar.gz
Algorithm Hash digest
SHA256 4f33c030619ed2be46fe602f30e774775f9ac3f14656c9a2fa2a4a1661e8ed42
MD5 ed72ca6253b5aec5bc8c1e69a31443aa
BLAKE2b-256 b2c926390c209551e9d0e59fcf564bd6eb2bad25159f4061b6179cf6add35171

See more details on using hashes here.

File details

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

File metadata

  • Download URL: forestiler-0.2.2a0-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.2a0-py3-none-any.whl
Algorithm Hash digest
SHA256 4bf280ef299d4a050e56db4941102fb1ad88508bcfdc8a79dbf544bbdb80a94c
MD5 6e1514c56263b50689381bdfc1ef1c33
BLAKE2b-256 a69026db462feef87f79232741ad6ebe6411b62435f6d09bb7f0b2d8e329f2cf

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