4 from typing import TextIO
8 from wrpylib.argparse_tools import bool_type
9 from wrpylib.wrgeojson import join_wrgeojson_ways, simplify_ways
12 def geojson_to_geojson(input: TextIO, output: TextIO, join_ways: bool, simplify: bool):
13 """'Converts' geojson to geojson
15 :param input: input geojson file
16 :param output: output geojson file
17 :param join_ways: joins subsequent ways of same type
18 :param simplify: true to simplify ways
20 wr_geojson = geojson.load(input)
21 if not wr_geojson.is_valid:
22 raise ValueError(f'Invalid GeoJSON: {wr_geojson.errors()}')
24 # Merge sledrun ways of the same type
26 join_wrgeojson_ways(wr_geojson)
28 # Simplify the sledrunMap
30 simplify_ways(wr_geojson)
33 geojson.dump(wr_geojson, output, ensure_ascii=False, indent=4)
37 parser = argparse.ArgumentParser(description='Converts Winterrodeln wrgeojson format to itself.'
38 'Reads from stdin, writes to stdout.')
39 parser.add_argument('--join-ways', type=bool_type, default=True,
40 help='joins subsequent ways of same type (default: True)')
41 parser.add_argument('--simplify', type=bool_type, default=False,
42 help='simplify the map (reduce number of points in paths) (default: False)')
43 args = parser.parse_args()
45 geojson_to_geojson(sys.stdin, sys.stdout, args.join_ways, args.simplify)
48 if __name__ == '__main__':