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
# 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:
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,
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
# 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:
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):
# 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:
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)')
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):
# 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:
-"""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
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)
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']
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]
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]