You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Cartopy创建挪威陆掩膜时遇urllib.error.HTTPError 404错误求解

解决Cartopy加载挪威陆掩膜时的404错误与下载警告

问题根源

你误用了shpreader.natural_earth()函数——这个函数仅用于从Natural Earth官方数据库下载标准shapefile资源,但你使用的挪威shapefile来自EEA,并非Natural Earth的标准资源,因此函数在Natural Earth服务器上找不到对应文件,触发404错误和下载警告。另外原代码中print(landmask_norway.ndim)会报错,因为landmask_norway是列表类型,没有ndim属性。


解决方案

方法一:加载本地已下载的EEA挪威shapefile

直接读取你从EEA下载并解压后的本地shapefile,无需通过natural_earth()函数:

# 替换为你本地解压后的shapefile完整路径(指向.shp文件)
norway_shp_path = '/your/local/path/no_1km_shp/no_1km.shp'
# 读取本地shapefile的几何数据
landmask_norway = list(shpreader.Reader(norway_shp_path).geometries())
# 遍历查看单个几何对象的维度(列表无ndim属性)
for geom in landmask_norway:
    print(geom.ndim)

方法二:使用Natural Earth官方挪威边界数据(低精度)

若可以接受较低精度的边界,直接调用natural_earth()加载官方提供的挪威数据:

# 加载Natural Earth的国家边界数据集
norway_shp = shpreader.natural_earth(resolution='110m', category='cultural', name='admin_0_countries')
reader = shpreader.Reader(norway_shp)
# 筛选出挪威的几何数据
landmask_norway = [geom for geom, rec in zip(reader.geometries(), reader.records()) 
                   if rec.attributes['NAME'] == 'Norway']
# 查看挪威几何对象的维度
if landmask_norway:
    print(landmask_norway[0].ndim)

内容的提问来源于stack exchange,提问作者Elsri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 20:22:49