在 Geopandas/Python 中从重叠多边形创建不同的非重叠多边形

问题描述 投票:0回答:1

给定一个具有一些重叠多边形(缓冲区)的 GeoDataFrame,我想在有重叠的地方创建独特的、非重叠的多边形,并保留非重叠的多边形。输出将没有重叠的多边形。使用要素转面工具可在 ArcMap/ArcGIS Desktop 中使用此功能:

https://pro.arcgis.com/en/pro-app/3.1/tool-reference/data-management/feature-to-polygon.htm

我尝试了很多不同的事情,但似乎不太正确。感谢您的帮助。

python gis geopandas
1个回答
0
投票

这看起来像geopandas提供的

由于您没有分享示例,因此这里有一个简单的示例来为您提供一般逻辑:

import geopandas as gpd
from shapely.geometry import Point, Polygon

geoms = gpd.GeoSeries([
    Point((1, 8)).buffer(2, cap_style=3),
    Polygon([Point((2, 3)), Point((2, 7)),
             Point((8, 7)), Point((8, 3))])])

gdf = gpd.GeoDataFrame({"id": [1, 2]}, geometry=geoms)

ov = gdf.overlay(gdf).query("id_1 != id_2") # how="intersection" by default

您也可以检查

intersection
。这里的
overlay
给出了两个相似的交点:

   id_1  id_2                                           geometry
1     2     1  POLYGON ((2.00000 7.00000, 3.00000 7.00000, 3....
2     1     2  POLYGON ((3.00000 6.00000, 2.00000 6.00000, 2....

要重现您共享的链接中的情节,请尝试以下操作:

import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 5))

gdf.plot(color="g", alpha=0.3, ec="k", ax=ax1)
gdf.plot(color=["#7da9da", "#df934d"], ec="k", ax=ax2)
ov.plot(color="#f7e172", ec="k", ax=ax2)

for i, x, y in zip(gdf["id"],
    gdf.geometry.centroid.x, gdf.geometry.centroid.y):
    for ax in (ax1, ax2):
        ax.text(x, y, i, ha="center", va="center", fontweight="bold")

ax2.text(ov.iloc[0].geometry.centroid.x.item(),
         ov.iloc[1].geometry.centroid.y.item(),
         "3", ha="center", va="center", fontweight="bold")

fd = fontdict={"weight": "bold"}
ax1.set_title("INPUT", **fd); ax2.set_title("OUTPUT", **fd)
ax1.axis("off"); ax2.axis("off")
plt.show();

© www.soinside.com 2019 - 2024. All rights reserved.