繁体   English   中英

一组几何的最小包络 - Geopandas

[英]Minimal Envelope of set of geometries - Geopandas

为了能够对 geopandas dataframe 中的一组几何图形进行操作,我需要能够确定对象是否位于集合的外部“边缘”。 几何集合如下:

在此处输入图像描述

为此,我想创建一个与几何对象集的外边界完美匹配的多边形。 我首先想到的是使用集合的凸包:

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)

在此处输入图像描述 在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM