-
Notifications
You must be signed in to change notification settings - Fork 1
/
OSWValidation.py
61 lines (51 loc) · 2.76 KB
/
OSWValidation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import argparse as ag
import os
import sys
import json
from OSWValidation.json_structure import validate_json_structure
from OSWValidation.validator import validate_with_schema
# from intersectingValidation import intersectLineStringInValidFormat
from glob import glob
# from node_connectivity import plot_nodes_vs_ways, subgraph_eda, get_invalidNodes
from config import DefaultConfigs
from OSWValidation.util_data import UtilData
# from Validate_JsonFile_Schema import validate_json_schema
import ntpath
from OSWValidation.util_defs import merge_dicts, write_outputs
import copy
if __name__ == '__main__':
parser = ag.ArgumentParser()
parser.add_argument("--inputPath", help="Relative input path to GeoJSON files. Default: TestData\input",
default=os.path.join(os.getcwd(), "TestData\input"))
parser.add_argument("--writePath", help="Relative output path to write the validation errors. Default: TestData\Output",
default=os.path.join(os.getcwd(), "TestData\Output"))
parser.add_argument("--schemaPath", help="Relative path to read the OSW schema document.")
args = parser.parse_args()
cf = DefaultConfigs(args)
json_files = glob(os.path.join(cf.inputPath, "*.geojson"))
print("Reading files from :", cf.inputPath)
print("Number of geojson files :", len(json_files))
nodes_files = sorted([x for x in json_files if 'node' in x.lower()])
ways_files = sorted([x for x in json_files if 'node' not in x.lower()])
for ind, ways_file in enumerate(ways_files):
print('Processing the following file : \n{}'.format(ntpath.basename(ways_file)))
utild = UtilData(ways_file, cf)
utildOriginal = copy.deepcopy(utild)
if cf.do_all_validations or cf.do_schema_validations:
# invalid_schema_nodes_dict = validate_json_schema(nodes_file, cf.node_schema, cf.writePath)
with open(ways_file, 'r') as fp:
ways_geojson = json.load(fp)
invalid_schema_ways_dict = validate_with_schema(ways_geojson, cf.schemaPath)
# invalid_nodes_dict, invalid_ways_dict = get_invalidNodes(utild, cf)
# merged_nodes_dict = merge_dicts(invalid_schema_nodes_dict, invalid_nodes_dict)
# merged_ways_dict = merge_dicts(invalid_schema_ways_dict, invalid_ways_dict)
write_outputs(utild, cf, invalid_schema_ways_dict)
# if cf.do_intersecting_validation:
# intersectLineStringInValidFormat(utildOriginal.ways_json, "brunnel", cf, ntpath.basename(ways_file))
# if cf.do_eda:
# print("--" * 10)
# print("eda")
# print("--" * 10)
#plot_nodes_vs_ways(utild, cf)
# subgraph_eda(utildOriginal, cf)
print("\n Output files written at the following location ", cf.writePath)