#!/usr/bin/python3 import argparse import sys from typing import TextIO import geojson import wrpylib.wrmwmarkup from wrpylib.argparse_tools import bool_type from wrpylib.wrgeojson import join_wrgeojson_ways, simplify_ways def wrmap_to_wrgeojson(input: TextIO, output: TextIO, join_ways: bool, simplify: bool): """Converts geojson to wrmap :param input: input geojson file :param output: output geojson file :param join_ways: joins subsequent ways of same type :param simplify: true to simplify ways """ wr_geojson = geojson.load(input) if not wr_geojson.is_valid: raise ValueError(f'Invalid GeoJSON: {wr_geojson.errors()}') # Merge sledrun ways of the same type if join_ways: join_wrgeojson_ways(wr_geojson) # Simplify the sledrunMap if simplify: simplify_ways(wr_geojson) # Print result print(wrpylib.wrmwmarkup.create_wrmap(wr_geojson), file=output) print('{{Landkarte Legende}}
{{GoogleMaps Hinweis}}') print() def main(): parser = argparse.ArgumentParser(description='Converts wrmap to wrgeojson format.' 'Reads from stdin, writes to stdout.') parser.add_argument('--join-ways', type=bool_type, default=True, help='joins subsequent ways of same type (default: True)') parser.add_argument('--simplify', type=bool_type, default=False, help='simplify the map (reduce number of points in paths) (default: False)') args = parser.parse_args() wrmap_to_wrgeojson(sys.stdin, sys.stdout, args.join_ways, args.simplify) if __name__ == '__main__': main()