Skip to main content

A very fast 2D concave hull algorithm

Project description

concave_hull

A very fast 2D concave hull algorithm.

Credits goes to:

Install

via pip

pip install concave_hull

from source

git clone --recursive https://github.com/cubao/concave_hull
pip install ./concave_hull

Or

pip install git+https://github.com/cubao/concave_hull.git

(you can build wheels for later reuse by pip wheel git+https://github.com/cubao/concave_hull.git)

Usage

Signature:

concave_hull_indexes(
       points: numpy.ndarray[numpy.float64[m, 2]],
       *,
       convex_hull_indexes: numpy.ndarray[numpy.int32[m, 1]],
       concavity: float = 2.0,
       length_threshold: float = 0.0,
) -> numpy.ndarray[numpy.int32[m, 1]]
  • concavity is a relative measure of concavity. 1 results in a relatively detailed shape, Infinity results in a convex hull. You can use values lower than 1, but they can produce pretty crazy shapes.
  • lengthThreshold: when a segment length is under this threshold, it stops being considered for further detalization. Higher values result in simpler shapes.

(document from https://github.com/mapbox/concaveman)

Example (see full code in test.py):

from concave_hull import concave_hull_indexes

idxes = concave_hull_indexes(
    points[:, :2],          # it's 2D concave hull, points should be N-by-2 numpy array
    convex_hull_indexes=convex_hull.vertices.astype(np.int32), # can be calculated by scipy
    length_threshold=50,
)

# you can get coordinates by `points[idxes]`

Tests

python3 test.py
python3 tests/test_basic.py

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

concave_hull-0.0.2.tar.gz (2.9 MB view hashes)

Uploaded Source

Built Distributions

concave_hull-0.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (87.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

concave_hull-0.0.2-cp310-cp310-macosx_11_0_arm64.whl (54.2 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

concave_hull-0.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (87.9 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

concave_hull-0.0.2-cp39-cp39-macosx_11_0_arm64.whl (54.3 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

concave_hull-0.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (87.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

concave_hull-0.0.2-cp38-cp38-macosx_11_0_arm64.whl (54.3 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

concave_hull-0.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (89.4 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

concave_hull-0.0.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (89.3 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

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