Commit 36cbeaa9 authored by Thomas Graichen's avatar Thomas Graichen

Add Readme and region code filtering as argument

parent 22576317
# OPENER ZHV Tools
This Python toolset can be used for converting ZHV data (German: Daten des Zentralen Haltestellenverzeichnisses) to OSM.
Use case of the converted data is the mapping of accessibility barriers at public transport stops with the [OPENER App](https://gitlab.hrz.tu-chemnitz.de/opener/opener-app).
The tool's software is licensed under the GPL 3.0.
Further information can be found at the German-speaking [project website of OPENER](https://www.bmvi.de/SharedDocs/DE/Artikel/DG/mfund-projekte/opener.html).
The development of this app is sponsored by the Federal Ministry of Transport and Digital Infrastructure under the project ID VB18F1016A
within the digital innovation program mFUND.
## Dependencies:
- Python 3.8
- pyosmium
- lxml
## Usage:
```shell
python ZhvConverter.py zHV_aktuell_xml.2020-05-05.xml --regionfilter SACHSEN
```
The output file is in your current working directory and has the name "yyyy-mm-dd-stop_places.osm" (e.g. 2020-05-08-stop_places.osm).
## XML-Scheme of ZHV:
The ZHV classes were generated by [generateDS](https://www.davekuhlman.org/generateDS.html) using a [ZHV XML scheme](data/scheme/zhv_scheme.xsd).
Regeneration of these classes can be done by:
```shell
generateDS -o ZhvClasses.py zhv_scheme.xsd
```
\ No newline at end of file
This diff is collapsed.
......@@ -7,7 +7,7 @@ from zhv_parser.ZhvClasses import StopPlace
class RegionCode(Enum):
ALL = ""
SCHLESWIG_HOLSTEIN = "01"
HAMBURG="02"
NIEDERSACHSEN="03"
......@@ -26,6 +26,8 @@ class RegionCode(Enum):
THUERINGEN = "16"
def isStopPlaceInRegion(self, stop_place: StopPlace):
if self == RegionCode.ALL:
return True
dhid = stop_place.get_DHID()
region_code = self.value
found = str(dhid).find(region_code, 3, 5)
......
import argparse
import os
import sys
from datetime import date
......@@ -88,7 +89,7 @@ class ZhvConverter:
def __init__(self):
self.unused_osm_id = 0
def parse(self, xml_file):
def parse(self, xml_file, region_code: RegionCode = RegionCode.ALL):
today = date.today()
# dd/mm/YY
d1 = today.strftime("%Y-%m-%d-")
......@@ -104,7 +105,7 @@ class ZhvConverter:
stop_place_class = ZhvClasses.StopPlace
stop_place = stop_place_class.factory()
stop_place.build(elem)
if not self.is_stop_place_in_region(RegionCode.SACHSEN, stop_place):
if not self.is_stop_place_in_region(region_code, stop_place):
continue
(stop_place_relation, nodes) = self.stop_place_to_osm(stop_place, context)
......@@ -240,11 +241,19 @@ def usage():
def main():
args = sys.argv[1:]
if len(args) != 1:
usage()
infile_name = args[0]
ZhvConverter().parse(infile_name)
parser = argparse.ArgumentParser()
parser.add_argument("inputfile", help="ZHV input file")
parser.add_argument("--regionfilter", help="zhv")
args = parser.parse_args()
infile_name = args.inputfile
if args.regionfilter:
region_code = RegionCode[args.regionfilter]
else:
region_code = RegionCode.ALL
print(f'Start conversion with region filer {region_code}')
ZhvConverter().parse(infile_name, region_code)
if __name__ == '__main__':
......
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