为了能够在地理数据集中的一组几何图形上进行操作,我需要能够确定物体是否在集合的外部“边缘”上。几何学的集合如下:
要做到这一点,我想要创建一个多边形,它与几何对象集合的外界完全匹配。我首先想到的是使用这个集合的凸包:
convex_hull = Sectioned_geostore_obstacles_geometry.unary_union.convex_hull
convex_hull = geopandas.GeoDataFrame({'geometry': convex_hull, 'convex_hull':[1]})
ax = Sectioned_geostore_obstacles_geometry['Gondola'].plot(color='red')
convex_hull.plot(ax=ax, color='green', alpha=0.5)
这会导致
但这是不完全正确的,因为我要寻找的不是凸的。第二个想法是使用信封:
envelope = Sectioned_geostore_obstacles_geometry.unary_union.envelope
envelope = geopandas.GeoDataFrame({'geometry': envelope, 'convex_hull':[1]})
ax = Sectioned_geostore_obstacles_geometry['Gondola'].plot(color='red')
envelope.plot(ax=ax, color='green', alpha=0.5)
这就是
再说一次,不是这样的。另一种尝试是使用shapely中的cascade_union功能:
from shapely.ops import cascaded_union
polygons = list(Sectioned_geostore_obstacles_geometry.Gondola)
boundary = gpd.GeoSeries(cascaded_union(polygons))
即:
但是,这也不是它,因为它返回一个多多边形,而不是最小的发展多边形。基本上,我需要信封收缩,以跟随一组物体的轮廓。
任何见解都将不胜感激。
为了测试这一点,我添加了以下示例数据:
test_df = geopandas.GeoSeries([Polygon([(0,0), (2,0), (2,2), (0,2)]),
Polygon([(2,2), (4,2), (4,4), (2,4)])])
test_df = geopandas.GeoDataFrame({'geometry': test_df, 'df1':[1,2]})
convex_hull = test_df.unary_union.convex_hull
convex_hull = geopandas.GeoDataFrame({'geometry': convex_hull, 'convex_hull':[1]})
ax1 = test_df['geometry'].plot(color='red')
convex_hull.plot(ax=ax1, color='green', alpha=0.5)
envelope = test_df.unary_union.envelope
envelope = geopandas.GeoDataFrame({'geometry': envelope, 'convex_hull':[1]})
ax2 = test_df['geometry'].plot(color='red')
envelope.plot(ax=ax2, color='green', alpha=0.5)
发布于 2022-04-14 14:01:44
https://stackoverflow.com/questions/71870815
复制相似问题