地geopandas-多角形到多边形几何形状

发布于 2025-02-03 03:39:15 字数 828 浏览 3 评论 0 原文

几何在我的Geopandas dataFrame中是类型 Polygon MultipolyGon 。我想将多龙门转换为多边形,因为我在数据上运行一些空间功能有问题。

示例数据文件:

from shapely.geometry import MultiPolygon, Polygon
import geopandas as gpd
from shapely import wkt
    
gdf = gpd.read_file()

# To GeoPandas
gdf['geometry'] = gdf['zip_code_geom'].apply(wkt.loads)

# Set Geometry
gdf = gdf.GeoDataFrame(df_rent_geo_v7, geometry='geometry')

# MultiPolygon to Polygon
gdf = gdf.explode(column='geometry', ignore_index=True, index_parts=False)

我尝试使用 [eskext] [1] [1] ,如其他类似问题,但是它不会将 Multipolygons 转换为多边形

geometry in my geopandas dataframe is of type Polygon and MultiPolygon. I'd like to convert the MultiPolygons to Polygons as I am having issues with running some spatial functions on the data.

Sample data file: https://www.dropbox.com/s/14ni2mfppt5dn7x/gdf%20%281%29.csv?dl=0

from shapely.geometry import MultiPolygon, Polygon
import geopandas as gpd
from shapely import wkt
    
gdf = gpd.read_file()

# To GeoPandas
gdf['geometry'] = gdf['zip_code_geom'].apply(wkt.loads)

# Set Geometry
gdf = gdf.GeoDataFrame(df_rent_geo_v7, geometry='geometry')

# MultiPolygon to Polygon
gdf = gdf.explode(column='geometry', ignore_index=True, index_parts=False)

I have tried using [explode][1] as suggested in other similar questions, but it doesn't convert MultiPolygons to Polygons.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睫毛溺水了 2025-02-10 03:39:15

您的示例数据中有不良的几何形状。这将转换有效的问题,并将坏的存储在BAD_GEOM_DICT中进行进一步调查。在有效的Geoms上爆炸作品。

bad_geom_dict = {}

for idx, row in gdf.iterrows():
    try:
        value = row['zip_code_geom']
        wkt.loads(value)
        gdf['geometry'] = wkt.loads(value)
    except Exception as e:
        print(e)
        bad_geom_dict[idx] = value

There are bad geometries in your example data. This will convert the valid ones and store the bad ones in the bad_geom_dict for further investigation. Explode works on the valid geoms.

bad_geom_dict = {}

for idx, row in gdf.iterrows():
    try:
        value = row['zip_code_geom']
        wkt.loads(value)
        gdf['geometry'] = wkt.loads(value)
    except Exception as e:
        print(e)
        bad_geom_dict[idx] = value
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文