简体   繁体   English

一组几何的最小包络 - Geopandas

[英]Minimal Envelope of set of geometries - Geopandas

To be able to do operations on a set of geometries in a geopandas dataframe, I need to be able to determine whether objects are on the outer "rim" of the set.为了能够对 geopandas dataframe 中的一组几何图形进行操作,我需要能够确定对象是否位于集合的外部“边缘”。 The set of geometries is as follows:几何集合如下:

在此处输入图像描述

To do this, I would like to create a polygon that perfectly matches the outer bound of the set of geometrical objects.为此,我想创建一个与几何对象集的外边界完美匹配的多边形。 I first thought about using the convex hull of the set:我首先想到的是使用集合的凸包:

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)

which results in这导致

在此处输入图像描述

but this isn't quite right since what I am looking for isn't convex.但这不太正确,因为我要找的不是凸的。 The second idea is to use the envelope:第二个想法是使用信封:

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)

which is这是

在此处输入图像描述

Again, this isn't it.再一次,这不是它。 Yet another attempt is to use the cascade_union functionality from shapely:另一种尝试是使用 shapely 中的 cascade_union 功能:

from shapely.ops import cascaded_union
polygons = list(Sectioned_geostore_obstacles_geometry.Gondola)
boundary = gpd.GeoSeries(cascaded_union(polygons))

which is:这是:

在此处输入图像描述

But, this isn't it either as it returns a multipolygon instead of the minimal eveloping polygon.但是,这不是它,因为它返回一个多多边形而不是最小的发展多边形。 Basically, I need the envelope to shrink to follow the contour of the set of objects.基本上,我需要缩小信封以跟随对象集的轮廓。

Any insights would be greatly appreciated.任何见解将不胜感激。

To test this, I add the following example data:为了对此进行测试,我添加了以下示例数据:

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