首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >计算重叠面积

计算重叠面积
EN

Stack Overflow用户
提问于 2020-04-04 02:54:31
回答 1查看 776关注 0票数 1

我正在学习这里的例子,并成功地创建了凸壳。但是,我有一个问题,如何计算每个凸壳之间的共享面积,如下图所示:

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-04 05:21:30

这里是曼哈顿和布朗克斯交汇处的一个例子。如果您想合并行政区,可以在pd.concat()之前使用.overlay()。

代码语言:javascript
复制
import geopandas as gpd
nybb_path = gpd.datasets.get_path('nybb')

boros = gpd.read_file(nybb_path)
boros.set_index('BoroCode', inplace=True)
boros.sort_index(inplace=True)

boros['geometry'] = boros['geometry'].convex_hull

print(boros)
    BoroName    Shape_Leng  Shape_Area  geometry
BoroCode                
1   Manhattan   359299.096471   6.364715e+08    POLYGON ((977855.445 188082.322, 971830.134 19...
2   Bronx   464392.991824   1.186925e+09    POLYGON ((1017949.978 225426.885, 1015563.562 ...
3   Brooklyn    741080.523166   1.937479e+09    POLYGON ((988872.821 146772.032, 983670.606 14...
4   Queens  896344.047763   3.045213e+09    POLYGON ((1000721.532 136681.776, 994611.996 2...
5   Staten Island   330470.010332   1.623820e+09    POLYGON ((915517.688 120121.881, 915467.035 12...

manhattan_gdf = boros.iloc[0:1, :]
bronx_gdf = boros.iloc[1:2, :]

manhattan_bronx_intersecetion_polygon = gpd.overlay(manhattan_gdf, bronx_gdf, 
how='intersection')

#SPCS83 New York Long Island zone (US Survey feet)
print(manhattan_bronx_intersecetion_polygon.geometry[0].area)
164559574.89341027

ax = manhattan_bronx_intersecetion_polygon.plot(figsize=(6,6))
boros.plot(ax=ax, facecolor='none', edgecolor='k');

这是一个循环解决方案,正如您在评论中所要求的那样。

代码语言:javascript
复制
import geopandas as gpd
nybb_path = gpd.datasets.get_path('nybb')

boros = gpd.read_file(nybb_path)
boros.set_index('BoroCode', inplace=True)
boros.sort_index(inplace=True)

boros['geometry'] = boros['geometry'].convex_hull

intersection_polygons_list = []

for idx, row in boros.iterrows():

    main_boro_gdf = boros.iloc[idx-1:idx, :]

    print('\n' + 'main boro:', main_boro_gdf['BoroName'].values.tolist()[:])

    other_boro_list = boros.index.tolist()

    other_boro_list.remove(idx)

    other_boro_gdf = boros[boros.index.isin(other_boro_list)]

    print('other boros:',other_boro_gdf['BoroName'].values.tolist()[:])

    intersection_polygons = gpd.overlay(main_boro_gdf, other_boro_gdf, how='intersection')

    intersection_polygons['intersection_area'] = intersection_polygons.geometry.area

    print('intersecton area sum:', intersection_polygons['intersection_area'].sum())

    intersection_polygons_list.append(intersection_polygons)

产出:

代码语言:javascript
复制
main boro: ['Manhattan']
other boros: ['Bronx', 'Brooklyn', 'Queens', 'Staten Island']
intersecton area sum: 279710750.6116526

main boro: ['Bronx']
other boros: ['Manhattan', 'Brooklyn', 'Queens', 'Staten Island']
intersecton area sum: 216638786.2669542

main boro: ['Brooklyn']
other boros: ['Manhattan', 'Bronx', 'Queens', 'Staten Island']
intersecton area sum: 1506573115.3550038

main boro: ['Queens']
other boros: ['Manhattan', 'Bronx', 'Brooklyn', 'Staten Island']
intersecton area sum: 1560297426.3563197

main boro: ['Staten Island']
other boros: ['Manhattan', 'Bronx', 'Brooklyn', 'Queens']
intersecton area sum: 0.0

可以使用intersection_polygons_list索引值绘制图表。例如,以下是布朗克斯区的重叠区域:

代码语言:javascript
复制
intersection_polygons_list[1].plot()

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61023237

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档