GeoJSON network simplification using raster image skeletonization and Voronoi polygons
Project description
parenx
Simplify (or "pare") a GeoJSON network ("nx") using raster image skeletonization an Voronoi polygons
Provides functions that use image skeletonization or Voronoi polygons to simplify geographic networks composed of linestrings. The outputs are geographic layers representing simplified or 'primal' representations of the network. Primal networks only contains straight line segments
Sample datasets include:
- Princes Street in Edinburgh, in data/rnet_princes_street.geojson
- Rail lines in Doncaster, in data/rnet_doncaster_rail.geojson
Installation
Install the package into an activated python virtual environment with the following command:
pip install parenx
Install the latest development version from GitHub with the following command:
pip install git+https://github.com/anisotropi4/parenx.git
This places the skeletonization.py and voronoi.py scripts into the executable search path.
Test to see if the package is installed with the following command:
python -c "import parenx; print(parenx.__version__)"
Examples
A bash helper script run.sh and example data is available under the sitepackage project directory under venv. The exact path varies with module and python version
Skeletonization
The following creates a simplified network by applying skeletonization to a buffered raster array in output.gpkg
# Download the data if not already present
if [ ! -f ./data/rnet_princes_street.geojson ]; then
wget https://raw.githubusercontent.com/anisotropi4/parenx/main/data/rnet_princes_street.geojson
# Create data folder if not already present
if [ ! -d ./data ]; then
mkdir ./data
fi
mv rnet_princes_street.geojson ./data
fi
skeletonize.py ./data/rnet_princes_street.geojson rnet_princes_street_skeletonized.gpkg
tile_skeletonize.py ./data/rnet_princes_street.geojson rnet_princes_street_skeletonized_tile.gpkg
Voronoi
The following creates a simplified network by creating set of Voronoi polygons from points on the buffer in output.gpkg
voronoi.py ./data/rnet_princes_street.geojson rnet_princes_street_voronoi.gpkg
Simple operation
The run.sh script sets a python virtual environment and executes the script against a data file in the data directory
$ ./run.sh
The run.sh script optionally takes a filename and file-extension. To simplify a file, say somewhere.geojson and output to GeoPKG files sk-simple.gpkg and vr-simple.gpkg
$ ./run.sh somewhere.geojon simple
Locating the run.sh script
To copy the run.sh script into your local directory the following could help
$ find . -name run.sh -exec cp {} . \;
Application Programming Interface (API) Example
The skeletonize_frame, voronoi_frame, primal_frame and tile_skeletonize_frame functions are exposed via a simple API.
#!/usr/bin/env python3
import geopandas as gp
from parenx import skeletonize_frame, voronoi_frame, skeletonize_tiles, get_primal
CRS = "EPSG:27700"
filepath = "data/rnet_princes_street.geojson"
frame = gp.read_file(filepath).to_crs(CRS)
parameter = {"simplify": 0.0, "buffer": 8.0, "scale": 1.0, "knot": False, "segment": False}
r = skeletonize_frame(frame["geometry"], parameter)
parameter = {"simplify": 0.0, "scale": 5.0, "buffer": 8.0, "tolerance": 1.0}
r = voronoi_frame(frame["geometry"], parameter)
primal = get_primal(r)
Notes
Both are the skeletonization and Voronoi approach are generic approaches, with the following known issues:
- This does not maintain a link between attributes and the simplified network
- This does not identify a subset of edges that need simplification
- The lines are a bit wobbly
- It is quite slow
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file parenx-0.7.0.tar.gz.
File metadata
- Download URL: parenx-0.7.0.tar.gz
- Upload date:
- Size: 180.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
700f0ae54faeb6f47a3d6a3ef75bd5f62cb47e5fa8eed0347d0361e0cc4ca5c0
|
|
| MD5 |
f7b0ee34199aa7615c6292dfb6183eea
|
|
| BLAKE2b-256 |
6dc5e8913218e9904f74f518bc7a31b482e8db19954a339e45ad75db5dfb932d
|
Provenance
The following attestation bundles were made for parenx-0.7.0.tar.gz:
Publisher:
release.yml on anisotropi4/parenx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
parenx-0.7.0.tar.gz -
Subject digest:
700f0ae54faeb6f47a3d6a3ef75bd5f62cb47e5fa8eed0347d0361e0cc4ca5c0 - Sigstore transparency entry: 310618032
- Sigstore integration time:
-
Permalink:
anisotropi4/parenx@dc4c42481fdcbe1b064f875542b422b2997f3b33 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/anisotropi4
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@dc4c42481fdcbe1b064f875542b422b2997f3b33 -
Trigger Event:
push
-
Statement type:
File details
Details for the file parenx-0.7.0-py3-none-any.whl.
File metadata
- Download URL: parenx-0.7.0-py3-none-any.whl
- Upload date:
- Size: 189.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
113a4df873bd05738c748eb40e016926bcd8b607abee6e9a953ea48d6c7b1b97
|
|
| MD5 |
bc0f83a38ba82ad3a925a315912169ab
|
|
| BLAKE2b-256 |
472ab7ee72276d760ce56371295ca3f8b1e1b56592469ae7920334827e1a1ef8
|
Provenance
The following attestation bundles were made for parenx-0.7.0-py3-none-any.whl:
Publisher:
release.yml on anisotropi4/parenx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
parenx-0.7.0-py3-none-any.whl -
Subject digest:
113a4df873bd05738c748eb40e016926bcd8b607abee6e9a953ea48d6c7b1b97 - Sigstore transparency entry: 310618040
- Sigstore integration time:
-
Permalink:
anisotropi4/parenx@dc4c42481fdcbe1b064f875542b422b2997f3b33 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/anisotropi4
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@dc4c42481fdcbe1b064f875542b422b2997f3b33 -
Trigger Event:
push
-
Statement type: