]> ToastFreeware Gitweb - philipp/winterrodeln/wrpylib.git/blob - scripts/wrmap_to_wrgeojson.py
VAO is missing important streets in Switzerland.
[philipp/winterrodeln/wrpylib.git] / scripts / wrmap_to_wrgeojson.py
1 #!/usr/bin/python3
2 import argparse
3 import sys
4 from typing import TextIO
5
6 import geojson
7
8 import wrpylib.wrmwmarkup
9 from wrpylib.argparse_tools import bool_type
10 from wrpylib.wrgeojson import join_wrgeojson_ways, simplify_ways
11
12
13 def wrmap_to_wrgeojson(input: TextIO, output: TextIO, join_ways: bool, simplify: bool):
14     """Converts geojson to wrmap
15
16     :param input: input geojson file
17     :param output: output geojson file
18     :param join_ways: joins subsequent ways of same type
19     :param simplify: true to simplify ways
20     """
21     wr_geojson = geojson.load(input)
22     if not wr_geojson.is_valid:
23         raise ValueError(f'Invalid GeoJSON: {wr_geojson.errors()}')
24
25     # Merge sledrun ways of the same type
26     if join_ways:
27         join_wrgeojson_ways(wr_geojson)
28
29     # Simplify the sledrunMap
30     if simplify:
31         simplify_ways(wr_geojson)
32
33     # Print result
34     print(wrpylib.wrmwmarkup.create_wrmap(wr_geojson), file=output)
35     print('{{Landkarte Legende}}<br/>{{GoogleMaps Hinweis}}')
36     print()
37
38
39 def main():
40     parser = argparse.ArgumentParser(description='Converts wrmap to wrgeojson format.'
41                                                  'Reads from stdin, writes to stdout.')
42     parser.add_argument('--join-ways', type=bool_type, default=True,
43                         help='joins subsequent ways of same type (default: True)')
44     parser.add_argument('--simplify', type=bool_type, default=False,
45                         help='simplify the map (reduce number of points in paths) (default: False)')
46     args = parser.parse_args()
47
48     wrmap_to_wrgeojson(sys.stdin, sys.stdout, args.join_ways, args.simplify)
49
50
51 if __name__ == '__main__':
52     main()