Skip to content

Commit 779b051

Browse files
Fix linting issues.
1 parent b424ac1 commit 779b051

File tree

1 file changed

+76
-47
lines changed

1 file changed

+76
-47
lines changed

xyzservices/data/generate_providers.py

Lines changed: 76 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,75 +2,104 @@
22
import xmltodict
33
import json
44

5-
with open('providers.json') as json_file:
5+
with open("providers.json") as json_file:
66
data = json.load(json_file)
77

8-
data['GeoportailFrance']['plan'] = {}
9-
data['GeoportailFrance']['orthos'] = {}
10-
data['GeoportailFrance']['parcels'] = {}
8+
data["GeoportailFrance"]["plan"] = {}
9+
data["GeoportailFrance"]["orthos"] = {}
10+
data["GeoportailFrance"]["parcels"] = {}
1111
tilelayers_list = []
12-
apikey_list = ['administratif', 'agriculture', 'altimetrie', 'cartes', 'clc', 'economie', 'environnement', 'essentiels', 'lambert93', 'ocsge', 'ortho', 'orthohisto', 'satellite', 'sol', 'topographie', 'transports']
13-
url_template = 'https://wxs.ign.fr/apikey/geoportail/wmts?REQUEST=GetCapabilities&SERVICE=wmts'
12+
apikey_list = [
13+
"administratif",
14+
"agriculture",
15+
"altimetrie",
16+
"cartes",
17+
"clc",
18+
"economie",
19+
"environnement",
20+
"essentiels",
21+
"lambert93",
22+
"ocsge",
23+
"ortho",
24+
"orthohisto",
25+
"satellite",
26+
"sol",
27+
"topographie",
28+
"transports",
29+
]
30+
url_template = (
31+
"https://wxs.ign.fr/apikey/geoportail/wmts?REQUEST=GetCapabilities&SERVICE=wmts"
32+
)
1433
for j in range(0, len(apikey_list)):
1534
apikey = apikey_list[j]
16-
url = url_template.replace('apikey', apikey)
35+
url = url_template.replace("apikey", apikey)
1736
resp = requests.get(url)
1837
resp_dict = xmltodict.parse(resp.content)
19-
layer_list = resp_dict['Capabilities']['Contents']['Layer']
38+
layer_list = resp_dict["Capabilities"]["Contents"]["Layer"]
2039
addictionnal_dict = {}
2140

2241
for i in range(len(layer_list)):
23-
layer = resp_dict['Capabilities']['Contents']['Layer'][i]
24-
variant = layer['ows:Identifier']
25-
name = ''
26-
if ('.' not in variant):
42+
layer = resp_dict["Capabilities"]["Contents"]["Layer"][i]
43+
variant = layer["ows:Identifier"]
44+
name = ""
45+
if "." not in variant:
2746
name = variant.lower().capitalize()
2847
else:
29-
name = variant.split('.')[0].lower().capitalize()
30-
for i in range(1, len(variant.split('.'))):
31-
name = name + '_' + (variant.split('.')[i]).lower().capitalize()
32-
name = name.replace('-', '_')
48+
name = variant.split(".")[0].lower().capitalize()
49+
for i in range(1, len(variant.split("."))):
50+
name = name + "_" + (variant.split(".")[i]).lower().capitalize()
51+
name = name.replace("-", "_")
3352

34-
if variant == 'GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2':
35-
name = 'plan'
36-
if variant == 'ORTHOIMAGERY.ORTHOPHOTOS':
37-
name = 'orthos'
38-
if variant == 'CADASTRALPARCELS.PARCELLAIRE_EXPRESS':
39-
name = 'parcels'
53+
if variant == "GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2":
54+
name = "plan"
55+
if variant == "ORTHOIMAGERY.ORTHOPHOTOS":
56+
name = "orthos"
57+
if variant == "CADASTRALPARCELS.PARCELLAIRE_EXPRESS":
58+
name = "parcels"
4059

41-
if 'Style' in layer.keys():
42-
if type(layer['Style']) is dict :
43-
style = layer['Style']['ows:Identifier']
60+
if "Style" in layer.keys():
61+
if type(layer["Style"]) is dict:
62+
style = layer["Style"]["ows:Identifier"]
4463

45-
elif type(layer['Style']) is list :
46-
style = layer['Style'][1]['ows:Identifier']
64+
elif type(layer["Style"]) is list:
65+
style = layer["Style"][1]["ows:Identifier"]
4766
else:
48-
style = 'normal'
67+
style = "normal"
4968

50-
TileMatrixSetLimits = layer['TileMatrixSetLink']['TileMatrixSetLimits']['TileMatrixLimits']
51-
min_zoom = int((TileMatrixSetLimits[0]['TileMatrix']))
52-
max_zoom = int((TileMatrixSetLimits[-1]['TileMatrix']))
53-
TileMatrixSet = layer['TileMatrixSetLink']['TileMatrixSet']
54-
format = layer['Format']
55-
bounding_lower_corner = layer['ows:WGS84BoundingBox']['ows:LowerCorner']
56-
bounding_upper_corner = layer['ows:WGS84BoundingBox']['ows:UpperCorner']
57-
lower1, lower2 = bounding_lower_corner.split(' ')
58-
upper1, upper2 = bounding_upper_corner.split(' ')
69+
TileMatrixSetLimits = layer["TileMatrixSetLink"]["TileMatrixSetLimits"][
70+
"TileMatrixLimits"
71+
]
72+
min_zoom = int((TileMatrixSetLimits[0]["TileMatrix"]))
73+
max_zoom = int((TileMatrixSetLimits[-1]["TileMatrix"]))
74+
TileMatrixSet = layer["TileMatrixSetLink"]["TileMatrixSet"]
75+
format = layer["Format"]
76+
bounding_lower_corner = layer["ows:WGS84BoundingBox"]["ows:LowerCorner"]
77+
bounding_upper_corner = layer["ows:WGS84BoundingBox"]["ows:UpperCorner"]
78+
lower1, lower2 = bounding_lower_corner.split(" ")
79+
upper1, upper2 = bounding_upper_corner.split(" ")
5980
bounds = [[float(lower1), float(lower2)], [float(upper1), float(upper2)]]
60-
for k in range(len(resp_dict['Capabilities']['Contents']['TileMatrixSet'])):
61-
supportedCRS = resp_dict['Capabilities']['Contents']['TileMatrixSet'][k]['ows:SupportedCRS']
81+
for k in range(len(resp_dict["Capabilities"]["Contents"]["TileMatrixSet"])):
82+
supportedCRS = resp_dict["Capabilities"]["Contents"]["TileMatrixSet"][k][
83+
"ows:SupportedCRS"
84+
]
6285

63-
if (format == 'application/x-protobuf'):
86+
if format == "application/x-protobuf":
6487
pass
65-
elif (format == 'image/x-bil;bits=32'):
88+
elif format == "image/x-bil;bits=32":
6689
pass
67-
elif (apikey == 'lambert93'):
90+
elif apikey == "lambert93":
6891
pass
6992
else:
7093
tilelayers_list.append("GeoportailFrance." + name)
71-
data['GeoportailFrance'][name] = {
72-
"url": "https://wxs.ign.fr/{apikey}/geoportail/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&STYLE={style}&TILEMATRIXSET={TileMatrixSet}&FORMAT={format}&LAYER={variant}&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}",
73-
"html_attribution": "<a target=\"_blank\" href=\"https://www.geoportail.gouv.fr/\">Geoportail France</a>",
94+
data["GeoportailFrance"][name] = {
95+
"url": """https://wxs.ign.fr/{apikey}/
96+
geoportail/wmts?REQUEST=GetTile&SERVICE=WMTS&
97+
VERSION=1.0.0&STYLE={style}&TILEMATRIXSET={TileMatrixSet}&
98+
FORMAT={format}&LAYER={variant}&
99+
TILEMATRIX={z}&TILEROW={y}&TILECOL={x}""",
100+
"html_attribution": """<a target="_blank"
101+
href="https://www.geoportail.gouv.fr/">
102+
Geoportail France</a>""",
74103
"attribution": "Geoportail France",
75104
"bounds": bounds,
76105
"min_zoom": min_zoom,
@@ -80,8 +109,8 @@
80109
"style": style,
81110
"variant": variant,
82111
"name": "GeoportailFrance." + name,
83-
"TileMatrixSet": TileMatrixSet
112+
"TileMatrixSet": TileMatrixSet,
84113
}
85114

86-
with open('new_providers.json', 'w') as fp:
115+
with open("new_providers.json", "w") as fp:
87116
json.dump(data, fp, indent=2)

0 commit comments

Comments
 (0)