cartopy.io.shapereader.NEShpDownloader#

class cartopy.io.shapereader.NEShpDownloader(url_template='https://naturalearth.s3.amazonaws.com/{resolution}_{category}/ne_{resolution}_{name}.zip', target_path_template=None, pre_downloaded_path_template='')[源代码]#

专注 cartopy.io.Downloader 下载压缩后的自然地球形状文件并将其提取到定义的位置(通常是用户可配置的)。

使用时应传递的键 format_dict 通常 category , resolutionname .

FORMAT_KEYS = ('config', 'resolution', 'category', 'name')#

中应提供的最低密钥 format_dict 论据 path , url , target_path , pre_downloaded_pathacquire_resource 方法.

acquire_resource(target_path, format_dict)[源代码]#

下载压缩文件并提取中列出的文件 zip_file_contents() 到达目标路径。

static default_downloader()[源代码]#

返回一个通用的、标准的NEShpDownloader实例。

通常,用户不需要调用此静态方法。

要查找NEShpDownloader的路径模板:

>>> ne_dnldr = NEShpDownloader.default_downloader()
>>> print(ne_dnldr.target_path_template)
{config[data_dir]}/shapefiles/natural_earth/{category}/ne_{resolution}_{name}.shp
static from_config(specification, config_dict=None)#

from_config 静态方法实现从配置字典获取Downloader(子)类实例的逻辑。

参数:
  • specification -- 应该是可迭代的,因为它将以相反的顺序进行迭代,以找到最适合此规范的下载器实例。 一个示例规范是 ('shapefiles', 'natural_earth') 用于自然地球形状文件。

  • config_dict (optional) -- 通常将其保留为“无”以使用默认值 cartopy.config “下载者”词典。

示例

>>> from cartopy.io import Downloader
>>>
>>> dnldr = Downloader('https://example.com/{name}', './{name}.txt')
>>> config = {('level_1', 'level_2'): dnldr}
>>> d1 = Downloader.from_config(('level_1', 'level_2', 'level_3'),
...                             config_dict=config)
>>> print(d1.url_template)
https://example.com/{name}
>>> print(d1.url({'name': 'item_name'}))
https://example.com/item_name
path(format_dict)#

返回此资源所代表的磁盘上文件的路径。

如果文件不存在于 pre_downloaded_path() 然后它会检查它是否存在于 target_path() ,否则资源将通过 acquire_resouce()url()target_path() .

通常,这是大多数应用程序都会调用的方法,允许新下载器的实现者专业化 acquire_resource() .

参数:

format_dict -- 用于替换某些模板变量的字典。子类应记录其中至少需要哪些键 FORMAT_KEYS 类属性。

pre_downloaded_path(format_dict)#

此资源所代表的文件在磁盘上的路径,如果它不存在,则不会对此路径采取进一步操作,并且所有进一步处理都将使用 target_path() 而不是.

参数:

format_dict -- 用于替换某些模板变量的字典。子类应记录其中至少需要哪些键 FORMAT_KEYS 类属性。

target_path(format_dict)#

此资源所代表的文件在磁盘上的路径必须存在或可由当前用户写。此方法不会检查这些条件中的任何一个。

参数:

format_dict -- 用于替换某些模板变量的字典。子类应记录其中至少需要哪些键 FORMAT_KEYS 类属性。

url(format_dict)#

此资源代表的完整URL。

参数:

format_dict -- 用于替换某些模板变量的字典。子类应记录其中至少需要哪些键 FORMAT_KEYS 类属性。

zip_file_contents(format_dict)[源代码]#

返回要在下载的自然地球压缩文件中找到的文件名的生成器。