今天是个好日子,
我有一个多点作为几何图形的集群地理数据。我能够使用 geopanda 的方法创建凸包convex_hull
。但不知何故,我找不到用于创建 alpha 形状的类似命令。或者一些东西会给我一个给定集群中所有点的紧密边界。
出于演示目的,我将在此处提供代码。该代码从 Open Street Map 下载样本数据,使用 HDBSCAN 方法对点进行聚类,然后为每个聚类创建凸包。
# 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
主要问题是关于最后一个命令。我想以类似的方式创建一个 alpha 形状(带有 predifend alpha 参数),我将拥有多边形,就像我在 convex_hull 的情况下一样。
有什么建议么?