使用多边形形状文件从大陆海岸线上删除岛屿 - GeoPandas

发布于 2025-01-21 02:23:25 字数 492 浏览 1 评论 0原文

我想从澳大利亚海岸线上删除所有断开的岛屿。我已经将该国作为一个Shapefile导入,可以使用硬编码边界删除区域。但是,在整个海岸线上追踪以去除所有断开的岛屿的效率是低效的。使用地理杂志有更快的方法吗?

import geoplot as gplt
import geopandas as gpd

Oz = gpd.read_file('OZ.shp')

#polygon = Polygon([(140, -40), (150, -40), (150, -45), (140,-45)])
#Oz_clip = gpd.clip(Oz, polygon)

I want to remove all disconnected islands from the Australian coastline. I've imported the country as a Shapefile and can remove regions using a hard-coded boundary. But it would be inefficient to trace around the entire coastline to remove all disconnected islands. Is there quicker method using GeoPandas?

import geoplot as gplt
import geopandas as gpd

Oz = gpd.read_file('OZ.shp')

#polygon = Polygon([(140, -40), (150, -40), (150, -45), (140,-45)])
#Oz_clip = gpd.clip(Oz, polygon)

enter image description here

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

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

发布评论

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

评论(1

喜爱纠缠 2025-01-28 02:23:25
import geopandas as gpd

gdf = gpd.read_file(
    "https://www.abs.gov.au/statistics/standards/australian-statistical-geography-standard-asgs-edition-3/jul2021-jun2026/access-and-downloads/digital-boundary-files/AUS_2021_AUST_SHP_GDA2020.zip"
)

# expand polygons and move to UTM geometry
polys = (
    gpd.GeoSeries(
        gdf.dropna()["geometry"].apply(lambda g: g.geoms).explode(), crs=gdf.crs
    )
    .to_crs(gdf.estimate_utm_crs())
    .simplify(100)
    .reset_index(drop=True)
)

# now build geodataframe limited by biggest area polygons
gdfm = (
    gpd.GeoDataFrame(data={"area": polys.area / 10**6}, geometry=polys, crs=polys.crs)
    .sort_values("area", ascending=0)
    # .head(3) # only one tasmania will be excluded
    .loc[lambda d: d["area"].gt(5000)]  # filter by size of polygon
    .reset_index()
)

# visualise
gdfm.explore(height=300, width=500)
    index   area    geometry
0   6411    7.787225e+06    POLYGON ((1023611.393 5771135.050, 1021232.002...
1   6373    6.490288e+04    POLYGON ((1497821.632 5153803.332, 1498006.176...
2   554 5.826181e+03    POLYGON ((26191.908 8735865.816, 26640.856 873..

进行最大面积多边形head()或面积超过阈值的多边形在此处输入图像描述

import geopandas as gpd

gdf = gpd.read_file(
    "https://www.abs.gov.au/statistics/standards/australian-statistical-geography-standard-asgs-edition-3/jul2021-jun2026/access-and-downloads/digital-boundary-files/AUS_2021_AUST_SHP_GDA2020.zip"
)

# expand polygons and move to UTM geometry
polys = (
    gpd.GeoSeries(
        gdf.dropna()["geometry"].apply(lambda g: g.geoms).explode(), crs=gdf.crs
    )
    .to_crs(gdf.estimate_utm_crs())
    .simplify(100)
    .reset_index(drop=True)
)

# now build geodataframe limited by biggest area polygons
gdfm = (
    gpd.GeoDataFrame(data={"area": polys.area / 10**6}, geometry=polys, crs=polys.crs)
    .sort_values("area", ascending=0)
    # .head(3) # only one tasmania will be excluded
    .loc[lambda d: d["area"].gt(5000)]  # filter by size of polygon
    .reset_index()
)

# visualise
gdfm.explore(height=300, width=500)
    index   area    geometry
0   6411    7.787225e+06    POLYGON ((1023611.393 5771135.050, 1021232.002...
1   6373    6.490288e+04    POLYGON ((1497821.632 5153803.332, 1498006.176...
2   554 5.826181e+03    POLYGON ((26191.908 8735865.816, 26640.856 873..

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文