Commit c8c01251 authored by Thomas Graichen's avatar Thomas Graichen

Consider false or missing data in ZHV

- we can even not rely on the existence of a DHID. Check this therefore.
parent 516fc858
......@@ -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
......@@ -144,7 +142,7 @@ class ZhvConverter:
elif elem.tag == tag_stop_place and action == event_end:
if len(list_stop_signs) == 0:
return None
return None, None
else:
# todo assign IDs of stop signs as members to stop place relation
for stop_sign in list_stop_signs:
......@@ -173,7 +171,10 @@ class ZhvConverter:
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
......@@ -181,16 +182,30 @@ class ZhvConverter:
""" 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()
try:
quay_dhid: str = quay.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)
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))
except:
pass
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)
......
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