Alpha Parameter in alphashape Python Library for Concave Hull Calculation

70 views Asked by At

I'm currently working on a geospatial analysis project in Python where I need to calculate the concave hull (alpha shape) of a set of geographical points. I'm using the alphashape library for this task. However, I'm facing an issue where changing the alpha parameter doesn't seem to alter the shape of the generated concave hull as expected.

I have a dataset of points (longitude and latitude) representing a small urban area. My goal is to create a concave hull that closely follows the contour of these points. However, even when varying the alpha parameter, the shape of the hull remains largely unchanged.

Here's the snippet of my code:

import pandas as pd
import matplotlib.pyplot as plt
import alphashape

# Load cluster data
data = pd.read_csv('myDir/cluster_0.csv', sep=';')

# Select longitude and latitude columns
points = data[['longitude', 'latitude']].values

# Visualize the concave hull for different alpha values
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
alphas = [0.01, 0.05, 0.1]  # Different alpha values to test

for ax, alpha in zip(axes, alphas):
    concave_hull = alphashape.alphashape(points, alpha)
    ax.scatter(data['longitude'], data['latitude'], color='blue')
    if concave_hull:
        x, y = concave_hull.exterior.xy
        ax.plot(x, y, color='red')
    ax.set_title(f'Alpha = {alpha}')
    ax.set_xlabel('Longitude')
    ax.set_ylabel('Latitude')

plt.tight_layout()
plt.show()

Sample with different alpha value

The visualization shows that the hull's shape doesn't significantly change with different alpha values. I was expecting a smaller alpha to produce a tighter fitting hull around the points.

Is there a common reason why the alpha parameter might not influence the hull shape as expected? Am I missing something in my approach, or is there a better way to determine an appropriate alpha value for a given set of data?

Any insights or suggestions would be greatly appreciated. Thank you!

1

There are 1 answers

0
label55 On

Oops, turns out I misunderstood the alphashape docs and his comprehension ! My alpha value just wasn't high enough for my dataset.

alpha_values = [30,50,80]

alpha 30 50 80

Thanks