]> ToastFreeware Gitweb - philipp/winterrodeln/wrpylib.git/commitdiff
Rename files so that the geojson based Winterrodeln map format is called wrgeojson.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Fri, 19 Aug 2022 21:00:21 +0000 (23:00 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Fri, 19 Aug 2022 21:00:21 +0000 (23:00 +0200)
scripts/geojson_to_geojson.py [deleted file]
scripts/geojson_to_wrmap.py [deleted file]
scripts/osm_to_geojson.py [deleted file]
scripts/osm_to_wrgeojson.py [new file with mode: 0644]
scripts/wrgeojson_to_wrgeojson.py [new file with mode: 0644]
scripts/wrgeojson_to_wrmap.py [new file with mode: 0644]

diff --git a/scripts/geojson_to_geojson.py b/scripts/geojson_to_geojson.py
deleted file mode 100644 (file)
index 99d957c..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/usr/bin/python3
-import argparse
-import sys
-from typing import TextIO
-
-import geojson
-
-from wrpylib.argparse_tools import bool_type
-from wrpylib.wrgeojson import join_sledrun_map_ways, simplify_ways
-
-
-def geojson_to_geojson(input: TextIO, output: TextIO, join_ways: bool, simplify: bool):
-    """'Converts' geojson to geojson
-
-    :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_sledrun_map_ways(wr_geojson)
-
-    # Simplify the sledrunMap
-    if simplify:
-        simplify_ways(wr_geojson)
-
-    # Print result
-    geojson.dump(wr_geojson, output, ensure_ascii=False, indent=4)
-
-
-def main():
-    parser = argparse.ArgumentParser(description='Converts Winterrodeln geojson format to itself.'
-                                     '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()
-
-    geojson_to_geojson(sys.stdin, sys.stdout, args.join_ways, args.simplify)
-
-
-if __name__ == '__main__':
-    main()
diff --git a/scripts/geojson_to_wrmap.py b/scripts/geojson_to_wrmap.py
deleted file mode 100644 (file)
index 8631395..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/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_sledrun_map_ways, simplify_ways
-
-
-def geojson_to_geojson(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_sledrun_map_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}}<br/>{{GoogleMaps Hinweis}}')
-    print()
-
-
-def main():
-    parser = argparse.ArgumentParser(description='Converts Winterrodeln geojson format to itself.'
-                                     '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()
-
-    geojson_to_geojson(sys.stdin, sys.stdout, args.join_ways, args.simplify)
-
-
-if __name__ == '__main__':
-    main()
diff --git a/scripts/osm_to_geojson.py b/scripts/osm_to_geojson.py
deleted file mode 100644 (file)
index 6cfc82e..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-#!/usr/bin/python3
-import argparse
-import json
-from typing import Optional
-from xml.etree.ElementTree import ElementTree
-
-from wrpylib.argparse_tools import bool_type
-from wrpylib.wrgeojson import join_sledrun_map_ways, simplify_ways
-from wrpylib.wrosm import find_sledrun_relations, tags, convert_osm_to_geojson, DeRefError
-
-
-def process_osm_file(filename: str, single: Optional[int], join_ways: bool, simplify: bool):
-    """converts an .osm file to <wrmap>(s).
-
-    :param filename: name of the .osm file
-    :param single: if not None, an int argument that specifies the number of the <wrmap> to display (1 based)
-    :param join_ways: joins subsequent ways of same type
-    :param simplify_max_dist: If not None, omit points to make the map file size smaller.
-        The float value gives the number of meters of way error that is maximally accepted.
-    """
-    osm_tree = ElementTree()
-    osm_tree.parse(filename)
-
-    # Search all sled run relations
-    sledrun_list = list(find_sledrun_relations(osm_tree))
-    if single is not None:
-        sledrun_list = [sledrun_list[single - 1]]
-
-    for sledrun_relation in sledrun_list:  # sledrun is an Element 'relation'
-        # Make a nice title
-        sledrun_tags = tags(sledrun_relation)
-        title = f"{sledrun_tags.get('name')} ({sledrun_tags.get('website')}) [{sledrun_relation.get('id')}]"
-        print(title)
-        print("-" * len(title))
-
-        # Convert to geojson
-        try:
-            sledrun_geojson = convert_osm_to_geojson(osm_tree, sledrun_relation)
-        except DeRefError:
-            print('Error: Incomplete XML - please load larger region.')
-            continue
-
-        # Merge sledrun ways of the same type
-        if join_ways:
-            join_sledrun_map_ways(sledrun_geojson)
-
-        # Simplify the sledrunMap
-        if simplify:
-            simplify_ways(sledrun_geojson)
-
-        # Print result
-        print(json.dumps(sledrun_geojson, ensure_ascii=False, indent=4))
-        print()
-
-
-def main():
-    epilog = "Writing result to a file without encoding errors:\n" + \
-             "$ PYTHONIOENCODING='ISO8859-15' python osm_to_geojson.py mymap.osm > mymap.json"
-    parser = argparse.ArgumentParser(description='Converts an OpenStreetMap .osm file to Winterrodeln geojson.',
-                                     epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter)
-    parser.add_argument('--single', type=int, help='just display the ith (1 based) <wrmap> instead of all')
-    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)')
-    parser.add_argument('osmfile', type=str, help='input file name (.osm file)')
-    args = parser.parse_args()
-
-    process_osm_file(args.osmfile, single=args.single, join_ways=args.join_ways, simplify=args.simplify)
-
-
-if __name__ == '__main__':
-    main()
diff --git a/scripts/osm_to_wrgeojson.py b/scripts/osm_to_wrgeojson.py
new file mode 100644 (file)
index 0000000..6cfc82e
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/python3
+import argparse
+import json
+from typing import Optional
+from xml.etree.ElementTree import ElementTree
+
+from wrpylib.argparse_tools import bool_type
+from wrpylib.wrgeojson import join_sledrun_map_ways, simplify_ways
+from wrpylib.wrosm import find_sledrun_relations, tags, convert_osm_to_geojson, DeRefError
+
+
+def process_osm_file(filename: str, single: Optional[int], join_ways: bool, simplify: bool):
+    """converts an .osm file to <wrmap>(s).
+
+    :param filename: name of the .osm file
+    :param single: if not None, an int argument that specifies the number of the <wrmap> to display (1 based)
+    :param join_ways: joins subsequent ways of same type
+    :param simplify_max_dist: If not None, omit points to make the map file size smaller.
+        The float value gives the number of meters of way error that is maximally accepted.
+    """
+    osm_tree = ElementTree()
+    osm_tree.parse(filename)
+
+    # Search all sled run relations
+    sledrun_list = list(find_sledrun_relations(osm_tree))
+    if single is not None:
+        sledrun_list = [sledrun_list[single - 1]]
+
+    for sledrun_relation in sledrun_list:  # sledrun is an Element 'relation'
+        # Make a nice title
+        sledrun_tags = tags(sledrun_relation)
+        title = f"{sledrun_tags.get('name')} ({sledrun_tags.get('website')}) [{sledrun_relation.get('id')}]"
+        print(title)
+        print("-" * len(title))
+
+        # Convert to geojson
+        try:
+            sledrun_geojson = convert_osm_to_geojson(osm_tree, sledrun_relation)
+        except DeRefError:
+            print('Error: Incomplete XML - please load larger region.')
+            continue
+
+        # Merge sledrun ways of the same type
+        if join_ways:
+            join_sledrun_map_ways(sledrun_geojson)
+
+        # Simplify the sledrunMap
+        if simplify:
+            simplify_ways(sledrun_geojson)
+
+        # Print result
+        print(json.dumps(sledrun_geojson, ensure_ascii=False, indent=4))
+        print()
+
+
+def main():
+    epilog = "Writing result to a file without encoding errors:\n" + \
+             "$ PYTHONIOENCODING='ISO8859-15' python osm_to_geojson.py mymap.osm > mymap.json"
+    parser = argparse.ArgumentParser(description='Converts an OpenStreetMap .osm file to Winterrodeln geojson.',
+                                     epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter)
+    parser.add_argument('--single', type=int, help='just display the ith (1 based) <wrmap> instead of all')
+    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)')
+    parser.add_argument('osmfile', type=str, help='input file name (.osm file)')
+    args = parser.parse_args()
+
+    process_osm_file(args.osmfile, single=args.single, join_ways=args.join_ways, simplify=args.simplify)
+
+
+if __name__ == '__main__':
+    main()
diff --git a/scripts/wrgeojson_to_wrgeojson.py b/scripts/wrgeojson_to_wrgeojson.py
new file mode 100644 (file)
index 0000000..99d957c
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/python3
+import argparse
+import sys
+from typing import TextIO
+
+import geojson
+
+from wrpylib.argparse_tools import bool_type
+from wrpylib.wrgeojson import join_sledrun_map_ways, simplify_ways
+
+
+def geojson_to_geojson(input: TextIO, output: TextIO, join_ways: bool, simplify: bool):
+    """'Converts' geojson to geojson
+
+    :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_sledrun_map_ways(wr_geojson)
+
+    # Simplify the sledrunMap
+    if simplify:
+        simplify_ways(wr_geojson)
+
+    # Print result
+    geojson.dump(wr_geojson, output, ensure_ascii=False, indent=4)
+
+
+def main():
+    parser = argparse.ArgumentParser(description='Converts Winterrodeln geojson format to itself.'
+                                     '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()
+
+    geojson_to_geojson(sys.stdin, sys.stdout, args.join_ways, args.simplify)
+
+
+if __name__ == '__main__':
+    main()
diff --git a/scripts/wrgeojson_to_wrmap.py b/scripts/wrgeojson_to_wrmap.py
new file mode 100644 (file)
index 0000000..8631395
--- /dev/null
@@ -0,0 +1,52 @@
+#!/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_sledrun_map_ways, simplify_ways
+
+
+def geojson_to_geojson(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_sledrun_map_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}}<br/>{{GoogleMaps Hinweis}}')
+    print()
+
+
+def main():
+    parser = argparse.ArgumentParser(description='Converts Winterrodeln geojson format to itself.'
+                                     '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()
+
+    geojson_to_geojson(sys.stdin, sys.stdout, args.join_ways, args.simplify)
+
+
+if __name__ == '__main__':
+    main()