Commit 22576317 authored by Thomas Graichen's avatar Thomas Graichen

Add stop places where the signs are missing as one node platform

parent c8c01251
......@@ -78,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
......@@ -108,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)
......@@ -142,17 +143,20 @@ class ZhvConverter:
elif elem.tag == tag_stop_place and action == event_end:
if len(list_stop_signs) == 0:
return None, 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>
......@@ -164,7 +168,7 @@ 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:
......@@ -178,46 +182,52 @@ class ZhvConverter:
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?
node_stop_sign: Node = Node()
node_stop_sign: Node = self.create_platform_node(quay, platform_type)
# return to previous structure hierarchy
for action, elem in context:
if elem.tag == tag_quay and action == event_end:
return node_stop_sign
def get_unused_osm_id(self):
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 = quay.get_DHID()
quay_dhid: str = zhv_element.get_DHID()
if quay_dhid is None:
raise ValueError('No DHID set!')
quay_lat: str = quay.get_Location().get_Latitude()
quay_lon: str = quay.get_Location().get_Longitude()
node_stop_sign.location = Location(quay_lon, quay_lat)
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 = quay.get_Name().get_Name()[0].get_valueOf_()
node_stop_sign.tags.append((osm_tag_ref[0], quay_name))
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_stop_sign.id = self.get_unused_osm_id()
node_stop_sign.tags = list()
node_stop_sign.tags.append((osm_tag_ref_ifopt[0], quay_dhid))
node_stop_sign.tags.append(osm_tag_platform_pt)
node_stop_sign.tags.append(stop_sign_type.value)
# return to previous structure hierarchy
for action, elem in context:
if elem.tag == tag_quay and action == event_end:
return node_stop_sign
def get_unused_osm_id(self):
self.unused_osm_id -= 1
return self.unused_osm_id
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>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment