Avto Abashishvili
Avto Abashishvili

Reputation: 453

Is there any command which will give me a alpha shape based on multipoint geometry?

Good Day Everyone,

I am having the clustered geodata which has a multipoint as a geometry. I am able to create convex hulls, using geopanda's method convex_hull. But somehow I was not able to find a similar command for creating an alpha shape. Or something which will give me a tight boundary around all the points in a given cluster.

For demonstrative purposes, I will provide the code here. The code downloads the sample data from Open Street Map, uses HDBSCAN method to cluster points and then creates the convex hull for each cluster.

# Import all necessary packages 

import pandas as pd
import geopandas as gpd
import osmnx as ox
from hdbscan import HDBSCAN
import numpy as np

# Get the sample data from OSM 
tags={"amenity": 'restaurant'}

place_name = 'San Diego'

sample = ox.geometries_from_place(
    place_name, tags={"amenity": ['restaurant', 'bar']}
)[["name", "geometry"]]

# Change crs to calculate centroids 

sample_albers = sample.to_crs(epsg=3311) # This is only the sample data. CRS might be wrong, but it is not the main focus here
sample_albers['point'] = sample_albers.centroid
sample_albers.set_geometry('point', inplace = True)

# Create lat and lon to cluster the data
lon_lat = np.column_stack((sample_albers['point'].x, sample_albers['point'].y)) 


# Apply HDBSCAN, get labels directly and dissolve the sample data by labels 

labels = HDBSCAN(min_cluster_size=10).fit(lon_lat).labels_

clusters = sample_albers[['point']].dissolve(by=labels)

# Creating Convex Hulls
clusters['convex_hull'] = clusters.convex_hull

The main question is regarding the last command. I want to create an alpha shape (with predifend alpha parameter) in a similar fashion where I will have the polygons just like I have in case of convex_hull.

Any suggestions?

Upvotes: 0

Views: 590

Answers (1)

BodoB
BodoB

Reputation: 414

This is now possible with GeoPandas. They added a method concave_hull(ratio=0.0, allow_holes=False).

The ratio parameter controls the shape of the hull. It has to be in the range [0, 1]. ratio=1 equals the convex hull.

To continue the above example:

# Creating Concave Hulls
clusters['concave_hull'] = clusters.concave_hull()

References

Upvotes: 0

Related Questions