This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_map_background.py
40 lines (35 loc) · 1.78 KB
/
add_map_background.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
##############################################################################################
# This file is deprecated because Python 2.x is deprecated #
# A Python 3.x version of this file can be found at: #
# #
# https://github.com/Guymer/PyGuymer3/blob/master/add_map_background.py #
##############################################################################################
def add_map_background(axis, debug = False, name = u"natural-earth-1", resolution = u"medium0512px"):
# Import modules ...
import json
import os
# Initialize trigger ...
default = True
# Check if the environment variable has been defined ...
if u"CARTOPY_USER_BACKGROUNDS" in os.environ:
# Determine JSON path and check it exists ...
jpath = os.path.join(os.environ[u"CARTOPY_USER_BACKGROUNDS"], u"images.json")
if os.path.exists(jpath):
# Load JSON and check keys exist ...
info = json.load(open(jpath, "rt"))
if name in info:
if resolution in info[name]:
# Determine image path and check it exists ...
ipath = os.path.join(os.environ[u"CARTOPY_USER_BACKGROUNDS"], info[name][resolution])
if os.path.exists(ipath):
default = False
# Draw background image ...
if default:
if debug:
print u"INFO: Drawing default background."
axis.stock_img()
else:
if debug:
print u"INFO: Drawing user-requested background."
axis.background_img(name = name, resolution = resolution)