Boundary

Calculate a Concave Hull for a collection of points given a maximum edge length as the parameter.

source

ConcaveHull

 ConcaveHull ()

Calculate the concave hull of a collection of points.


source

ConcaveHull.loadpoints

 ConcaveHull.loadpoints (points:list)

Point format: [[x1, y1], [x2, y2], [x3, y3], …]
or [[x1, y1, z1], [x2, y2, z2], [x3, y3, z3], …]


source

ConcaveHull.calculatehull

 ConcaveHull.calculatehull (tol:float=50)

Calculates the concave hull

Parameters: tol (float) : All border edges longer than this parameter will be attempted to be removed.

Returns: None


source

ConcaveHull.estimate

 ConcaveHull.estimate (perc:float=92.5)

Gives an estimate of the val to be used in tol for calculatehull to yeild a nice looking concave hull

Parameters:
perc (float) : Number between 0 and 100

Returns:
(float) : Suggested value to use as tol in calculatehull


source

ConcaveHull.boundary_points

 ConcaveHull.boundary_points ()

Returns a list of the boundary points

Parameters:
None

Returns:
(list) : List of coordinates of the pints on the hull boundary


source

ConcaveHull.plot

 ConcaveHull.plot (figsize:float=5)

Plot the points and the concave hull

Parameters:
figsize(float) : The figure size in inches. The apsect ratio is set to 1. The x or y axis of your plot will be adjusted accordingly.

Usage Example

Example of a real strip survey from on a section of road.

with open('../examples/BANDELIER8.TXT') as source:
    points = list()
    for i, pt in enumerate(source):
        items = pt.split()
        if i <= 5:
           print(items)
        x, y, z = float(items[1]), float(items[2]), float(items[3])
        points.append((x, y))
print()
print('Number of points in the survey:', len(points))
['STN9', '88609.53', '-2573311.58', '1071.33']
['FE1000', '88611.22', '-2573309.87', '1071.30', 'Fenline']
['FE1001', '88612.12', '-2573310.23', '1071.40', 'Fenline']
['FE1002', '88624.42', '-2573296.98', '1071.45', 'Fenline']
['FE1003', '88636.30', '-2573283.87', '1070.87', 'Fenline']
['FE1004', '88651.24', '-2573273.17', '1070.39', 'Fenline']

Number of points in the survey: 12275

The tol parameter in the calculatehull method is in this case expressed as metres. All boundary edges greater than this will be investigated for possible removal.

Boundary edges longer than this can possibly remain if the the triangle has two boundary edges already. No points will be left “stranded” outside the hull.

Depending on the input points the tol parameter can be in degrees or feet as well.

ch = ConcaveHull()
ch.loadpoints(points)
ch.calculatehull(tol=35)

print()
print('Number of points on the boundary:', len(ch.boundary_points()))
print()

Number of points on the boundary: 1675

CPU times: user 301 ms, sys: 7.25 ms, total: 308 ms
Wall time: 307 ms
ch.plot(figsize=18)

If there is an uncertainty on which value to use for the tol parameter the estimate method can be used to provide a starting value.

estimate = ch.estimate()
print(estimate)
30.13064834845798
ch.calculatehull(tol=estimate)

print()
print('Number of points on the boundary:',len(ch.boundary_points()))
print()

Number of points on the boundary: 1975