]> ToastFreeware Gitweb - philipp/winterrodeln/wrpylib.git/commitdiff
Start to consitenly call Winterrodeln geojson wrgeojson.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Fri, 19 Aug 2022 21:05:28 +0000 (23:05 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Fri, 19 Aug 2022 21:05:28 +0000 (23:05 +0200)
scripts/osm_to_wrgeojson.py
scripts/osm_to_wrmap.py
scripts/wrgeojson_to_wrgeojson.py
scripts/wrgeojson_to_wrmap.py
wrpylib/wrgeojson.py

index 6cfc82e6975aa161411bf7d162c12b44082a1587..5d8dcb556e86446f30f0ca65675caa3602e2ec99 100644 (file)
@@ -5,7 +5,7 @@ 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.wrgeojson import join_wrgeojson_ways, simplify_ways
 from wrpylib.wrosm import find_sledrun_relations, tags, convert_osm_to_geojson, DeRefError
 
 
@@ -42,7 +42,7 @@ def process_osm_file(filename: str, single: Optional[int], join_ways: bool, simp
 
         # Merge sledrun ways of the same type
         if join_ways:
-            join_sledrun_map_ways(sledrun_geojson)
+            join_wrgeojson_ways(sledrun_geojson)
 
         # Simplify the sledrunMap
         if simplify:
@@ -55,8 +55,8 @@ def process_osm_file(filename: str, single: Optional[int], join_ways: bool, simp
 
 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.',
+             "$ PYTHONIOENCODING='ISO8859-15' python osm_to_wrgeojson.py mymap.osm > mymap.json"
+    parser = argparse.ArgumentParser(description='Converts an OpenStreetMap .osm file to wrgeojson.',
                                      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,
index e57577c48bf1b417be397a0348fe5a17c4cda79b..66c17d9f23c869c8274e3eba8264b05c4ffaa2a1 100644 (file)
@@ -27,7 +27,7 @@ from xml.etree.ElementTree import ElementTree
 import wrpylib.wrmwmarkup
 
 from wrpylib.argparse_tools import bool_type
-from wrpylib.wrgeojson import join_sledrun_map_ways, simplify_ways
+from wrpylib.wrgeojson import join_wrgeojson_ways, simplify_ways
 from wrpylib.wrosm import find_sledrun_relations, tags, convert_osm_to_geojson, DeRefError
 
 
@@ -63,7 +63,7 @@ def process_osm_file(filename: str, single: Optional[int], join_ways: bool, simp
 
         # Merge sledrun ways of the same type
         if join_ways:
-            join_sledrun_map_ways(sledrun_geojson)
+            join_wrgeojson_ways(sledrun_geojson)
 
         # Simplify the sledrunMap
         if simplify is not None:
index 99d957c744b40e42a52f54809fe5050d117e8054..a1b11e48f34e5f49ebfd78daf94b16a9cc0ecf28 100644 (file)
@@ -6,7 +6,7 @@ from typing import TextIO
 import geojson
 
 from wrpylib.argparse_tools import bool_type
-from wrpylib.wrgeojson import join_sledrun_map_ways, simplify_ways
+from wrpylib.wrgeojson import join_wrgeojson_ways, simplify_ways
 
 
 def geojson_to_geojson(input: TextIO, output: TextIO, join_ways: bool, simplify: bool):
@@ -23,7 +23,7 @@ def geojson_to_geojson(input: TextIO, output: TextIO, join_ways: bool, simplify:
 
     # Merge sledrun ways of the same type
     if join_ways:
-        join_sledrun_map_ways(wr_geojson)
+        join_wrgeojson_ways(wr_geojson)
 
     # Simplify the sledrunMap
     if simplify:
@@ -34,7 +34,7 @@ def geojson_to_geojson(input: TextIO, output: TextIO, join_ways: bool, simplify:
 
 
 def main():
-    parser = argparse.ArgumentParser(description='Converts Winterrodeln geojson format to itself.'
+    parser = argparse.ArgumentParser(description='Converts Winterrodeln wrgeojson 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)')
index 863139593f184f51e706477864c434e61e1b58f6..184e44093b5028a7158b11d1854849acd35520d1 100644 (file)
@@ -7,7 +7,7 @@ import geojson
 
 import wrpylib.wrmwmarkup
 from wrpylib.argparse_tools import bool_type
-from wrpylib.wrgeojson import join_sledrun_map_ways, simplify_ways
+from wrpylib.wrgeojson import join_wrgeojson_ways, simplify_ways
 
 
 def geojson_to_geojson(input: TextIO, output: TextIO, join_ways: bool, simplify: bool):
@@ -24,7 +24,7 @@ def geojson_to_geojson(input: TextIO, output: TextIO, join_ways: bool, simplify:
 
     # Merge sledrun ways of the same type
     if join_ways:
-        join_sledrun_map_ways(wr_geojson)
+        join_wrgeojson_ways(wr_geojson)
 
     # Simplify the sledrunMap
     if simplify:
index 371c99b440eb8c526307a248ec9c96402b5c90fa..6cb0a39c10f3143ae9a1798221d11d345e608ad0 100644 (file)
@@ -1,4 +1,5 @@
-"""Winterrodeln maps can be represented in the GeoJSON format. This module contains related helper functions.
+"""Winterrodeln maps can be represented in the GeoJSON format - this is referred to as wrgeojson.
+This module contains related helper functions.
 
 A Winterrodeln  map is represented as `feature collection`.
 The properties are
@@ -186,8 +187,8 @@ def simplify_way(lon_lat_list: List[Tuple[float, ...]], max_dist: float):
 DEFAULT_MAX_DIST_ERROR_M = 15.
 
 
-def simplify_ways(feature_collection: FeatureCollection, max_dist: float = DEFAULT_MAX_DIST_ERROR_M):
-    ways = [feature for feature in feature_collection['features'] if feature["geometry"]["type"] == "LineString"]
+def simplify_ways(wrgeojson: FeatureCollection, max_dist: float = DEFAULT_MAX_DIST_ERROR_M):
+    ways = [feature for feature in wrgeojson['features'] if feature["geometry"]["type"] == "LineString"]
     for way in ways:
         simplify_way(way['geometry']['coordinates'], max_dist)
 
@@ -202,13 +203,13 @@ def find_center(coordinates: Iterable[Tuple[float, ...]], fallback: Tuple[float,
     return (min_lon + max_lon) / 2., (min_lat + max_lat) / 2.
 
 
-def find_map_center(feature_collection: FeatureCollection, fallback: Tuple[float, float]) -> Tuple[float, float]:
+def find_map_center(wrgeojson: FeatureCollection, fallback: Tuple[float, float]) -> Tuple[float, float]:
     # Calculate center of the map
-    coordinates = geojson.utils.coords(feature_collection)
+    coordinates = geojson.utils.coords(wrgeojson)
     return find_center(coordinates, fallback)
 
 
-def sort_features(feature_collection: FeatureCollection) -> FeatureCollection:
+def sort_features(wrgeojson: FeatureCollection) -> FeatureCollection:
     """Sort the features of the sledruns in preferred order of rendering"""
     def sort_key(feature: Feature) -> Tuple[int, int]:
         geometry_type = feature['geometry']['type']
@@ -220,15 +221,15 @@ def sort_features(feature_collection: FeatureCollection) -> FeatureCollection:
         else:
             order = ['gasthaus', 'haltestelle', 'parkplatz', 'warnung', 'punkt']  # the left types are coming first
             return 0, order.index(feature_type)
-    feature_collection.features = sorted(feature_collection.features, key=sort_key)
-    return feature_collection
+    wrgeojson.features = sorted(wrgeojson.features, key=sort_key)
+    return wrgeojson
 
 
-def join_sledrun_map_ways(sledrun_map: FeatureCollection, preserve_crossing=False):
+def join_wrgeojson_ways(wrgeojson: FeatureCollection, preserve_crossing=False):
     """Unite ways of the same type of sled runs."""
     # Get crossing (lon, lat) tuples as list.
     # Crossings are positions (lon, lat) that occur at least three way-edges.
-    ways = [feature for feature in sledrun_map['features'] if feature["geometry"]["type"] == "LineString"]
+    ways = [feature for feature in wrgeojson['features'] if feature["geometry"]["type"] == "LineString"]
     coord_count = Counter(geojson.utils.coords(ways))
     crossing_list = [coord for coord, count in coord_count.items() if count >= 3]
 
@@ -272,5 +273,5 @@ def join_sledrun_map_ways(sledrun_map: FeatureCollection, preserve_crossing=Fals
                     ways[j]['geometry']['coordinates'].clear()
                 j += 1
         i += 1
-    sledrun_map['features'] = [f for f in sledrun_map['features']
-                               if f['geometry']['type'] != 'LineString' or len(f['geometry']['coordinates']) > 0]
+    wrgeojson['features'] = [f for f in wrgeojson['features']
+                             if f['geometry']['type'] != 'LineString' or len(f['geometry']['coordinates']) > 0]