rainflame / geopolygonize

Convert geographic rasters into simplified polygons
https://rainflame.github.io/geopolygonize/
1 stars 0 forks source link

Geopolygonize

Convert geographic rasters into simplified polygons. Given an input raster file, this tool produces a gpkg file representation of the raster that simplifies out pixelation. It also maintains shapes' relations to one another such that the output is guaranteed to have no gaps.

Here's an example of this in action with an area that shows the Three Sisters in Oregon, near Bend.

Input (rendered in QGIS):

Output (rendered in QGIS):

Algorithm

Most existing methods for polygon simplification such as the Douglas–Peucker simplification algorithm or concave hulls operate on a single polygon at a time. This presents a problem when run on a collection of polygons that fit together perfectly–simplifying each polygon separately will introduce unpredictable gaps. Our algorithm takes an approach similar to TopoJSON. It identifies the boundaries shared between polygons, simplifies those boundaries, then assigns the simplified boundaries back to the polygons. This results in simplified polygons that fit perfectly together without any gaps.

Install

pip install geopolygonize

Quickstart

To convert a raster to simplified polygons, run:

geopolygonize --input-file="data/input.tif" --output-file="data/output.shp"

Options + API

Refer to the docs.

Development

This package requires the use of Python 3.10 or above.

Create a virtual environment:

python3.10 -m venv .venv

Install the dependencies:

pip install -r requirements.txt

Then, run the CLI:

python -m src.clean --input-file="data/input.tif" --output-file="data/cleaned.tif"
python -m src.geopolygonize --input-file="data/cleaned.tif" --output-file="data/output.shp"

Test against some existing input:

./tests/run_e2e_test.sh <input>

Find test raster inputs here.

Tests are under tests/ and are Jupyter Notebooks.

First install jupyter in the virtual environment:

pip install jupyter

Use the virtual environment's jupyter to access the tests:

.venv/bin/jupyter-lab