...
 
Commits (2)
......@@ -6,9 +6,7 @@ from typing import Sequence
import osmium
from lxml import etree
from osmium.osm import create_mutable_relation, create_mutable_node
from osmium.osm import Location
from osmium.osm._osm import RelationMember
from osmium.osm.mutable import Relation, Node
from zhv_parser import ZhvClasses
......@@ -80,7 +78,7 @@ osm_tag_fixme_type_unknown = ('fixme', 'Ist diese Haltestelle für Straßenbahne
# For trams: https://wiki.openstreetmap.org/wiki/Tag:railway%3Dtram_stop
class StopSignType(Enum):
class PlatformType(Enum):
BUS = osm_tag_highway_bus_stop_sign
TRAM = osm_tag_platform_railway
UNKNOWN = osm_tag_fixme_type_unknown
......@@ -110,6 +108,7 @@ class ZhvConverter:
continue
(stop_place_relation, nodes) = self.stop_place_to_osm(stop_place, context)
if stop_place_relation is not None:
for node in nodes:
writer.add_node(node)
......@@ -144,17 +143,20 @@ class ZhvConverter:
elif elem.tag == tag_stop_place and action == event_end:
if len(list_stop_signs) == 0:
return None
else:
# todo assign IDs of stop signs as members to stop place relation
for stop_sign in list_stop_signs:
stop_place_relation.members.append(tuple([osm_relation_type_node, stop_sign.id, osm_relation_role_platform]))
node_platform = self.create_platform_node(stop_place, PlatformType.UNKNOWN)
if node_platform is None:
return None, None
else:
list_stop_signs.append(node_platform)
for stop_sign in list_stop_signs:
stop_place_relation.members.append(tuple([osm_relation_type_node, stop_sign.id, osm_relation_role_platform]))
return stop_place_relation, list_stop_signs
return stop_place_relation, list_stop_signs
def area_to_osm(self, area: Area, context) -> Sequence[Node]:
list_nodes = list()
# extract type of stop sign (Bus, Tram, etc.?) -> unfortunately, there is no standard attribute for this
# TODO: extract type of stop sign (Bus, Tram, etc.?) -> unfortunately, there is no standard attribute for this
# One possible criteria for bus/tram distinguishing: (used by HannIT)
# <Description>
# <Description>Bus</Description>
......@@ -166,33 +168,25 @@ class ZhvConverter:
# name = area.get_Name().get_Name()[0].get_valueOf_()
# description = area.get_
stop_sign_type = StopSignType.UNKNOWN
stop_sign_type = PlatformType.UNKNOWN
for action, elem in context:
if elem.tag == tag_quay and action == event_start:
quay_class = ZhvClasses.Quay
quay = quay_class.factory()
quay.build(elem)
list_nodes.append(self.quay_to_osm(quay, stop_sign_type, context))
node = self.quay_to_osm(quay, stop_sign_type, context)
if node is not None:
list_nodes.append(node)
elif elem.tag == tag_area and action == event_end:
return list_nodes
def quay_to_osm(self, quay: Quay, stop_sign_type: StopSignType , context) -> Node:
def quay_to_osm(self, quay: Quay, platform_type: PlatformType, context) -> Node:
""" Extract an OSM node from the given ZHV stop sign structure """
# extract quay parameters
# TODO: Ask ZHV: Why are names double encapsulated?
quay_name: str = quay.get_Name().get_Name()[0].get_valueOf_()
quay_dhid: str = quay.get_DHID()
quay_lat: str = quay.get_Location().get_Latitude()
quay_lon: str = quay.get_Location().get_Longitude()
node_stop_sign: Node = Node()
node_stop_sign.id = self.get_unused_osm_id()
node_stop_sign.location = Location(quay_lon, quay_lat)
node_stop_sign.tags = list()
node_stop_sign.tags.append((osm_tag_ref_ifopt[0], quay_dhid))
node_stop_sign.tags.append((osm_tag_ref[0], quay_name))
node_stop_sign.tags.append(osm_tag_platform_pt)
node_stop_sign.tags.append(stop_sign_type.value)
node_stop_sign: Node = self.create_platform_node(quay, platform_type)
# return to previous structure hierarchy
for action, elem in context:
......@@ -203,6 +197,37 @@ class ZhvConverter:
self.unused_osm_id -= 1
return self.unused_osm_id
def create_platform_node(self, zhv_element, platform_type: PlatformType) -> Node:
if not isinstance(zhv_element, (StopPlace, Area, Quay)):
return None
node_platform: Node = Node()
try:
quay_dhid: str = zhv_element.get_DHID()
if quay_dhid is None:
raise ValueError('No DHID set!')
quay_lat: str = zhv_element.get_Location().get_Latitude()
quay_lon: str = zhv_element.get_Location().get_Longitude()
node_platform.location = Location(quay_lon, quay_lat)
except Exception as error:
print(error)
return None
# todo exception handling
try:
quay_name: str = zhv_element.get_Name().get_Name()[0].get_valueOf_()
node_platform.tags.append((osm_tag_ref[0], quay_name))
except:
pass
node_platform.id = self.get_unused_osm_id()
node_platform.tags = list()
node_platform.tags.append((osm_tag_ref_ifopt[0], quay_dhid))
node_platform.tags.append(osm_tag_platform_pt)
node_platform.tags.append(platform_type.value)
return node_platform
USAGE_TEXT = """
Usage: python ???.py <infilename>
......