|
2 | 2 | import xmltodict
|
3 | 3 | import json
|
4 | 4 |
|
5 |
| -with open('providers.json') as json_file: |
| 5 | +with open("providers.json") as json_file: |
6 | 6 | data = json.load(json_file)
|
7 | 7 |
|
8 |
| -data['GeoportailFrance']['plan'] = {} |
9 |
| -data['GeoportailFrance']['orthos'] = {} |
10 |
| -data['GeoportailFrance']['parcels'] = {} |
| 8 | +data["GeoportailFrance"]["plan"] = {} |
| 9 | +data["GeoportailFrance"]["orthos"] = {} |
| 10 | +data["GeoportailFrance"]["parcels"] = {} |
11 | 11 | 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 | +) |
14 | 33 | for j in range(0, len(apikey_list)):
|
15 | 34 | apikey = apikey_list[j]
|
16 |
| - url = url_template.replace('apikey', apikey) |
| 35 | + url = url_template.replace("apikey", apikey) |
17 | 36 | resp = requests.get(url)
|
18 | 37 | resp_dict = xmltodict.parse(resp.content)
|
19 |
| - layer_list = resp_dict['Capabilities']['Contents']['Layer'] |
| 38 | + layer_list = resp_dict["Capabilities"]["Contents"]["Layer"] |
20 | 39 | addictionnal_dict = {}
|
21 | 40 |
|
22 | 41 | 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: |
27 | 46 | name = variant.lower().capitalize()
|
28 | 47 | 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("-", "_") |
33 | 52 |
|
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" |
40 | 59 |
|
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"] |
44 | 63 |
|
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"] |
47 | 66 | else:
|
48 |
| - style = 'normal' |
| 67 | + style = "normal" |
49 | 68 |
|
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(" ") |
59 | 80 | 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 | + ] |
62 | 85 |
|
63 |
| - if (format == 'application/x-protobuf'): |
| 86 | + if format == "application/x-protobuf": |
64 | 87 | pass
|
65 |
| - elif (format == 'image/x-bil;bits=32'): |
| 88 | + elif format == "image/x-bil;bits=32": |
66 | 89 | pass
|
67 |
| - elif (apikey == 'lambert93'): |
| 90 | + elif apikey == "lambert93": |
68 | 91 | pass
|
69 | 92 | else:
|
70 | 93 | 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>""", |
74 | 103 | "attribution": "Geoportail France",
|
75 | 104 | "bounds": bounds,
|
76 | 105 | "min_zoom": min_zoom,
|
|
80 | 109 | "style": style,
|
81 | 110 | "variant": variant,
|
82 | 111 | "name": "GeoportailFrance." + name,
|
83 |
| - "TileMatrixSet": TileMatrixSet |
| 112 | + "TileMatrixSet": TileMatrixSet, |
84 | 113 | }
|
85 | 114 |
|
86 |
| -with open('new_providers.json', 'w') as fp: |
| 115 | +with open("new_providers.json", "w") as fp: |
87 | 116 | json.dump(data, fp, indent=2)
|
0 commit comments