Created
July 9, 2020 10:27
-
-
Save arbakker/a02e765cf6e7a2c92ef092293ed32062 to your computer and use it in GitHub Desktop.
python script voor het omkatten van BRTA WMTS requests naar OZON VT WMTS RESTful requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ | |
| python script voor het omkatten van BRTA WMTS urls naar OZON VT WMTS RESTful requests | |
| input csv moet er zo uit zien: | |
| "https://geodata.nationaalgeoregister.nl","/tiles/service/wmts","SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=brtachtergrondkaart&STYLE=default&TILEMATRIXSET=EPSG%3A28992&TILEMATRIX=EPSG%3A28992%3A3&TILEROW=4&TILECOL=4&FORMAT=image%2Fpng8" | |
| """ | |
| import csv | |
| import click | |
| import re | |
| HOST="https://service.pdok.nl" | |
| def capture_expected_group(pattern, input_string): | |
| m = re.search(pattern, input_string) | |
| if len(m.groups())>0: | |
| return m.groups(1)[0] | |
| return "" | |
| @click.command() | |
| @click.argument('csv-file-input', type=click.Path(exists=True)) | |
| @click.argument('csv-file-output', type=click.Path(exists=False)) | |
| def main(csv_file_input, csv_file_output): | |
| with open(csv_file_input) as csv_file, open(csv_file_output, "w") as output_file: | |
| csv_reader = csv.reader(csv_file, delimiter=',') | |
| csv_writer = csv.writer(output_file, delimiter=',', quotechar="'") | |
| for row in csv_reader: | |
| query_string = row[2] | |
| if "TILEMATRIXSET=EPSG:28992" in query_string: | |
| x = capture_expected_group('^.*TILECOL=([0-9]+).*$', query_string) | |
| y = capture_expected_group('^.*TILEROW=([0-9]+).*$', query_string) | |
| z = capture_expected_group('^.*TILEMATRIX=(.*?)&.*$', query_string) | |
| if ":" in z: | |
| z = z.split(":")[2] | |
| z = str(int(z)) | |
| if int(z) > 10: | |
| continue | |
| path=f"/kadaster/ozon/wmts/v1_0-preprod/locaties/EPSG:28992/{z}/{x}/{y}.pbf" | |
| csv_writer.writerow([f"\"{HOST}\"", f"\"{path}\"", "\"\""]) | |
| if __name__=="__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment