Commit 6822c5ab authored by Thomas Graichen's avatar Thomas Graichen

Add support for region code filter

parent d6620e03
from enum import Enum
# This is representing the first two digits of Germany's "Amtlicher Gemeindeschlüssel":
# https://www.destatis.de/DE/Themen/Laender-Regionen/Regionales/Gemeindeverzeichnis/Glossar/amtlicher-gemeindeschluessel.html
from zhv_parser.ZHV_Classes import StopPlace
class RegionCode(Enum):
SCHLESWIG_HOLSTEIN = "01"
HAMBURG="02"
NIEDERSACHSEN="03"
BREMEN="04"
NORDRHEIN_WESTFALEN="05"
HESSEN="06"
RHEINLAND_PFALZ = "07"
BADEN_WUERTEMBERG = "08"
BAYERN = "09"
SAARLAND = "10"
BERLIN = "11"
BRANDENBURG = "12"
MECKLENBURG_VORPOMMERN = "13"
SACHSEN = "14"
SACHSEN_ANHALT = "15"
THUERINGEN = "16"
def isStopPlaceInRegion(self, stop_place: StopPlace):
dhid = stop_place.get_DHID()
region_code = self.value
found = str(dhid).find(region_code, 3, 5)
if found == -1:
return False
else:
return True
......@@ -4,22 +4,28 @@ from io import StringIO
from lxml import etree
from zhv_parser import ZHV_Classes
from zhv_parser.RegionCode import RegionCode
from zhv_parser.ZHV_Classes import StopPlace
def parse(xml_file):
#f = StringIO(xml_file)
context = etree.iterparse(xml_file, events=("start",), tag="{http://zhv.xml.wvi/}StopPlace")
for action, node in context:
stop_place_class = ZHV_Classes.StopPlace
stop_place = stop_place_class.factory()
stop_place.build(node)
print(stop_place)
if is_stop_place_in_region(RegionCode.BRANDENBURG, stop_place):
print(stop_place)
convert_to_osm(stop_place)
else:
print("Not in Region!")
def isStopPlaceInRegion(stop_place):
pass
def is_stop_place_in_region(region_code: RegionCode, stop_place: StopPlace):
return region_code.isStopPlaceInRegion(stop_place)
def convertToOSM(stop_place):
def convert_to_osm(stop_place: StopPlace):
"""Converts stop place to an OSM object """
pass
......
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