4 from typing import TextIO
8 import wrpylib.wrmwmarkup
9 from wrpylib.argparse_tools import bool_type
10 from wrpylib.wrgeojson import join_wrgeojson_ways, simplify_ways
13 def wrmap_to_wrgeojson(input: TextIO, output: TextIO, join_ways: bool, simplify: bool):
14 """Converts geojson to wrmap
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
21 wr_geojson = geojson.load(input)
22 if not wr_geojson.is_valid:
23 raise ValueError(f'Invalid GeoJSON: {wr_geojson.errors()}')
25 # Merge sledrun ways of the same type
27 join_wrgeojson_ways(wr_geojson)
29 # Simplify the sledrunMap
31 simplify_ways(wr_geojson)
34 print(wrpylib.wrmwmarkup.create_wrmap(wr_geojson), file=output)
35 print('{{Landkarte Legende}}<br/>{{GoogleMaps Hinweis}}')
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()
48 wrmap_to_wrgeojson(sys.stdin, sys.stdout, args.join_ways, args.simplify)
51 if __name__ == '__main__':