Giter VIP home page Giter VIP logo

concavity's Introduction

concavity

Concave Hull boundary polygon for an array of points and concave and convex polygon vertex detection

Concavity is a small python module that implements a concave hull algorithm following Moreira, Adriano & Santos, Maribel. (2007) [1], based on k-nearest-neighbors. It also implements an algorithm for concave and convex vertices detection on a polygon's exterior and interiors, and plot them for EDA.

Main Features

  • Concave hull algorithm implementation for an array of points (based on Moreira, Adriano & Santos, Maribel. (2007) [1])
  • Finding concave and convex vertices on a polygon's boundary based on an angle threshold and peak detection
  • Simple plotting for EDA

Examples

  • Create a concave hull polygon from a set of coordinates based on k-nearest neighbors
#create a synthetic set of points:
import numpy as np
from shapely.geometry import Point
import geopandas as gpd
import matplotlib.pyplot as plt
import concavity

np.random.seed(seed=456)
x = np.random.normal(100000,500, 1000)
y = np.random.normal(100000, 500, 1000)
coords = np.array(list(zip(x, y)))
gpd.GeoSeries([Point(c) for c in coords]).plot()

create a concave hull polygon based on 20 nearest neighbors:

ch = concavity.concave_hull(coords, 20)
ch

plot concave hull polygon based on 50 nearest neighbors and compare with a convex hull polygon

ch = concavity.concave_hull(coords, 50)
concavity.plot_concave_hull(coords, ch)

create a more elaborate concave hull polygon based on 30 nearest neighbors and compare with a convex hull polygon using plot_concave_hull

ch = concavity.concave_hull(coords, 30)
concavity.plot_concave_hull(coords, ch)

create an even more elaborate boundary based on 15 nearest neighbors

ch = concavity.concave_hull(coords, 15)
concavity.plot_concave_hull(coords, ch)

  • Find concave and convex vertices on a polygon boundary

The find_concave_vertices and find_concave_vertices functions take a polygon, an angle_threshold as the minimum angle above which a vertex is in a concave/convex location and a filter type that determines if the function outputs all point above the angle threshold or will attempt to locate the peak concave/convex vertices. the output type can be either ageopandas GeoDataFrame or a list of vertices and the angle of the two edges they connect

Here we choose to output all the concave/convex:

concave_df = concavity.find_concave_vertices(ch,0, filter_type ='all')
convex_df = concavity.find_convex_vertices(ch,0, filter_type ='all')
concavity.plot_vertices(ch, concave_df, convex_df)

To make a less obvious example - let's smooth our polygon and try again

from concavity.utils import gaussian_smooth_geom
geom = gaussian_smooth_geom( ch)
concave_df = concavity.find_concave_vertices(geom,0, filter_type ='all')
convex_df = concavity.find_convex_vertices(geom,0, filter_type ='all')
concavity.plot_vertices(geom, concave_df, convex_df)

Here we let the algorithm detect only the peak concave and convex vertices

concave_df = concavity.find_concave_vertices(geom,0, filter_type ='peak')
convex_df = concavity.find_convex_vertices(geom,0, filter_type ='peak')
concavity.plot_vertices(geom, concave_df, convex_df)

We can smooth the angles by using the convovle boolean argument and refine even further the vertices that will be marked as peaks

concave_df = concavity.find_concave_vertices(geom,0, filter_type ='peak', convolve = True)
convex_df = concavity.find_convex_vertices(geom,0, filter_type ='peak', convolve = True)
concavity.plot_vertices(geom, concave_df, convex_df)

Use the angle threshold argument to limit the angles above which a vertex is considered convex/concave:

concave_df = concavity.find_concave_vertices(geom,angle_threshold=10, filter_type ='peak')
convex_df = concavity.find_convex_vertices(geom,angle_threshold=10, filter_type ='peak')
concavity.plot_vertices(geom, concave_df, convex_df)

  1. Moreira, Adriano & Santos, Maribel. (2007). Concave hull: A k-nearest neighbours approach for the computation of the region occupied by a set of points.. 61-68.

concavity's People

Contributors

mlichter2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

concavity's Issues

concavity.concave_hull() never finishes on point clouds with over ~6500 points

Hello,

I'm using this module to clip rasters generated from point clouds to the border of the cloud. concavity.concave_hull() works lightning fast on any cloud with less than around 6500 points, but right when you get into that range, it just pauses forever, never finishing. Any ideas on what might cause this? I've tried many different values for knn, with no change.

Thank you,
Beau

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.