python-osw-validation 0.2.6__py3-none-any.whl → 0.2.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_osw_validation/__init__.py +30 -11
- python_osw_validation/extracted_data_validator.py +47 -35
- python_osw_validation/version.py +1 -1
- {python_osw_validation-0.2.6.dist-info → python_osw_validation-0.2.7.dist-info}/METADATA +2 -2
- python_osw_validation-0.2.7.dist-info/RECORD +10 -0
- python_osw_validation-0.2.6.dist-info/RECORD +0 -10
- {python_osw_validation-0.2.6.dist-info → python_osw_validation-0.2.7.dist-info}/LICENSE +0 -0
- {python_osw_validation-0.2.6.dist-info → python_osw_validation-0.2.7.dist-info}/WHEEL +0 -0
- {python_osw_validation-0.2.6.dist-info → python_osw_validation-0.2.7.dist-info}/top_level.txt +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import gc
|
|
3
3
|
import json
|
|
4
|
-
import
|
|
5
|
-
from typing import Dict, Any, Optional, List
|
|
4
|
+
import jsonschema_rs
|
|
6
5
|
import geopandas as gpd
|
|
7
6
|
from .zipfile_handler import ZipFileHandler
|
|
7
|
+
from typing import Dict, Any, Optional, List
|
|
8
8
|
from .extracted_data_validator import ExtractedDataValidator, OSW_DATASET_FILES
|
|
9
9
|
from .version import __version__
|
|
10
10
|
|
|
@@ -37,7 +37,7 @@ class OSWValidation:
|
|
|
37
37
|
except Exception as e:
|
|
38
38
|
self.errors.append(f'Invalid or missing schema file: {e}')
|
|
39
39
|
raise Exception(f'Invalid or missing schema file: {e}')
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
def are_ids_unique(self, gdf):
|
|
42
42
|
"""Check for duplicate values in the _id field"""
|
|
43
43
|
duplicates = gdf[gdf.duplicated('_id', keep=False)]['_id'].unique()
|
|
@@ -47,6 +47,7 @@ class OSWValidation:
|
|
|
47
47
|
def validate(self, max_errors=20) -> ValidationResult:
|
|
48
48
|
zip_handler = None
|
|
49
49
|
OSW_DATASET = {}
|
|
50
|
+
validator = None
|
|
50
51
|
try:
|
|
51
52
|
# Extract the zipfile
|
|
52
53
|
zip_handler = ZipFileHandler(self.zipfile_path)
|
|
@@ -73,7 +74,8 @@ class OSWValidation:
|
|
|
73
74
|
# Validate data integrity
|
|
74
75
|
for file in validator.files:
|
|
75
76
|
file_path = os.path.join(file)
|
|
76
|
-
osw_file = next(
|
|
77
|
+
osw_file = next(
|
|
78
|
+
(osw_file_any for osw_file_any in OSW_DATASET_FILES.keys() if osw_file_any in file_path), '')
|
|
77
79
|
OSW_DATASET[osw_file] = gpd.read_file(file_path)
|
|
78
80
|
|
|
79
81
|
# Are all id's unique in each file? No need to check uniqueness across files yet since we do not have a global OSW ID format yet
|
|
@@ -104,26 +106,32 @@ class OSWValidation:
|
|
|
104
106
|
unmatched = node_ids_edges_u - node_ids
|
|
105
107
|
is_valid = len(unmatched) == 0
|
|
106
108
|
if not is_valid:
|
|
107
|
-
self.errors.append(
|
|
109
|
+
self.errors.append(
|
|
110
|
+
f"All _u_id's in edges should be part of _id's mentioned in nodes, _u_id's not in nodes are: {unmatched}")
|
|
108
111
|
|
|
109
112
|
# Do all node references in _v_id exist in nodes?
|
|
110
113
|
unmatched = node_ids_edges_v - node_ids
|
|
111
114
|
is_valid = len(unmatched) == 0
|
|
112
115
|
if not is_valid:
|
|
113
|
-
self.errors.append(
|
|
116
|
+
self.errors.append(
|
|
117
|
+
f"All _v_id's in edges should be part of _id's mentioned in nodes, _v_id's not in nodes are: {unmatched}")
|
|
114
118
|
|
|
115
119
|
# Do all node references in _w_id exist in nodes?
|
|
116
120
|
unmatched = node_ids_zones_w - node_ids
|
|
117
121
|
is_valid = len(unmatched) == 0
|
|
118
122
|
if not is_valid:
|
|
119
|
-
self.errors.append(
|
|
123
|
+
self.errors.append(
|
|
124
|
+
f"All _w_id's in zones should be part of _id's mentioned in nodes, _w_id's not in nodes are: {unmatched}")
|
|
120
125
|
|
|
121
126
|
# Geometry validation: check geometry type in each file and test if coordinates make a shape that is reasonable geometric shape according to the Simple Feature Access standard
|
|
122
127
|
for osw_file in OSW_DATASET:
|
|
123
|
-
invalid_geojson = OSW_DATASET[osw_file][
|
|
128
|
+
invalid_geojson = OSW_DATASET[osw_file][
|
|
129
|
+
(OSW_DATASET[osw_file].geometry.type != OSW_DATASET_FILES[osw_file]['geometry']) | (
|
|
130
|
+
OSW_DATASET[osw_file].is_valid == False)]
|
|
124
131
|
is_valid = len(invalid_geojson) == 0
|
|
125
132
|
if not is_valid:
|
|
126
|
-
self.errors.append(
|
|
133
|
+
self.errors.append(
|
|
134
|
+
f"Invalid {osw_file} geometries found, id's of invalid geometries: {set(invalid_geojson['_id'])}")
|
|
127
135
|
|
|
128
136
|
# Validate OSW external extensions
|
|
129
137
|
for file in validator.externalExtensions:
|
|
@@ -132,7 +140,8 @@ class OSWValidation:
|
|
|
132
140
|
invalid_geojson = extensionFile[extensionFile.is_valid == False]
|
|
133
141
|
is_valid = len(invalid_geojson) == 0
|
|
134
142
|
if not is_valid:
|
|
135
|
-
self.errors.append(
|
|
143
|
+
self.errors.append(
|
|
144
|
+
f"Invalid geometries found in extension file {file}, list of invalid geometries: {invalid_geojson.to_json()}")
|
|
136
145
|
|
|
137
146
|
if self.errors:
|
|
138
147
|
return ValidationResult(False, self.errors)
|
|
@@ -145,6 +154,16 @@ class OSWValidation:
|
|
|
145
154
|
del OSW_DATASET
|
|
146
155
|
if zip_handler:
|
|
147
156
|
zip_handler.remove_extracted_files()
|
|
157
|
+
|
|
158
|
+
# Force garbage collection to free memory
|
|
159
|
+
gc.collect()
|
|
160
|
+
|
|
161
|
+
# Additional memory cleanup for geopandas dataframes
|
|
162
|
+
if validator:
|
|
163
|
+
for osw_file in validator.files:
|
|
164
|
+
if osw_file in locals():
|
|
165
|
+
del osw_file
|
|
166
|
+
del validator
|
|
148
167
|
gc.collect()
|
|
149
168
|
|
|
150
169
|
def load_osw_file(self, graph_geojson_path: str) -> Dict[str, Any]:
|
|
@@ -155,7 +174,7 @@ class OSWValidation:
|
|
|
155
174
|
def validate_osw_errors(self, file_path: str, max_errors: int) -> bool:
|
|
156
175
|
"""Validate OSW Data against the schema and process all errors"""
|
|
157
176
|
geojson_data = self.load_osw_file(file_path)
|
|
158
|
-
validator =
|
|
177
|
+
validator = jsonschema_rs.Draft7Validator(self.load_osw_schema(self.schema_file_path))
|
|
159
178
|
|
|
160
179
|
for error in validator.iter_errors(geojson_data):
|
|
161
180
|
self.errors.append(f'Validation error: {error.message}')
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import gc
|
|
2
3
|
import glob
|
|
3
4
|
|
|
4
5
|
OSW_DATASET_FILES = {
|
|
@@ -57,44 +58,55 @@ class ExtractedDataValidator:
|
|
|
57
58
|
optional_files = [key for key, value in OSW_DATASET_FILES.items() if not value['required']]
|
|
58
59
|
missing_files = []
|
|
59
60
|
duplicate_files = []
|
|
60
|
-
|
|
61
|
-
file_count = 0
|
|
62
|
-
for filename in geojson_files:
|
|
63
|
-
base_name = os.path.basename(filename)
|
|
64
|
-
if required_file in base_name and base_name.endswith('.geojson'):
|
|
65
|
-
file_count += 1
|
|
66
|
-
save_filename = filename
|
|
67
|
-
if file_count == 0:
|
|
68
|
-
# Missing required file
|
|
69
|
-
missing_files.append(required_file)
|
|
70
|
-
elif file_count == 1:
|
|
71
|
-
self.files.append(save_filename)
|
|
72
|
-
else:
|
|
73
|
-
# Duplicate file
|
|
74
|
-
duplicate_files.append(required_file)
|
|
61
|
+
save_filename = None # Initialize this variable
|
|
75
62
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
for
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
63
|
+
try:
|
|
64
|
+
# Process required files
|
|
65
|
+
for required_file in required_files:
|
|
66
|
+
file_count = 0
|
|
67
|
+
for filename in geojson_files:
|
|
68
|
+
base_name = os.path.basename(filename)
|
|
69
|
+
if required_file in base_name and base_name.endswith('.geojson'):
|
|
70
|
+
file_count += 1
|
|
71
|
+
save_filename = filename
|
|
72
|
+
if file_count == 0:
|
|
73
|
+
# Missing required file
|
|
74
|
+
missing_files.append(required_file)
|
|
75
|
+
elif file_count == 1:
|
|
76
|
+
self.files.append(save_filename)
|
|
77
|
+
else:
|
|
78
|
+
# Duplicate file
|
|
79
|
+
duplicate_files.append(required_file)
|
|
88
80
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
81
|
+
# Process optional files
|
|
82
|
+
for optional_file in optional_files:
|
|
83
|
+
file_count = 0
|
|
84
|
+
for filename in geojson_files:
|
|
85
|
+
base_name = os.path.basename(filename)
|
|
86
|
+
if optional_file in base_name and base_name.endswith('.geojson'):
|
|
87
|
+
file_count += 1
|
|
88
|
+
save_filename = filename
|
|
89
|
+
if file_count == 1:
|
|
90
|
+
self.files.append(save_filename)
|
|
91
|
+
elif file_count > 1:
|
|
92
|
+
# Duplicate file
|
|
93
|
+
duplicate_files.append(optional_file)
|
|
92
94
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
# Check for missing or duplicate files
|
|
96
|
+
if missing_files:
|
|
97
|
+
self.error = f'Missing required .geojson files: {", ".join(missing_files)}.'
|
|
98
|
+
return False
|
|
99
|
+
|
|
100
|
+
if duplicate_files:
|
|
101
|
+
self.error = f'Multiple .geojson files of the same type found: {", ".join(duplicate_files)}.'
|
|
102
|
+
return False
|
|
103
|
+
|
|
104
|
+
# Add OSW external extensions, GeoJSON files we know nothing about
|
|
105
|
+
self.externalExtensions.extend([item for item in geojson_files if item not in self.files])
|
|
96
106
|
|
|
97
|
-
|
|
98
|
-
|
|
107
|
+
finally:
|
|
108
|
+
# Cleanup large lists and call garbage collector
|
|
109
|
+
del geojson_files, required_files, optional_files, missing_files, duplicate_files
|
|
110
|
+
gc.collect()
|
|
99
111
|
|
|
100
112
|
return True
|
python_osw_validation/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = '0.2.
|
|
1
|
+
__version__ = '0.2.7'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-osw-validation
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: Python library for OSW validation
|
|
5
5
|
Home-page: https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation
|
|
6
6
|
Author: Sujata Misra
|
|
@@ -14,7 +14,7 @@ Classifier: Operating System :: OS Independent
|
|
|
14
14
|
Requires-Python: >=3.10
|
|
15
15
|
Description-Content-Type: text/markdown
|
|
16
16
|
License-File: LICENSE
|
|
17
|
-
Requires-Dist: jsonschema
|
|
17
|
+
Requires-Dist: jsonschema-rs
|
|
18
18
|
Requires-Dist: zipfile36
|
|
19
19
|
Requires-Dist: geopandas
|
|
20
20
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
python_osw_validation/__init__.py,sha256=SKFTjvZC_TGYH45jVkdq-MctbZLMrX6ElXp88BzCfdg,7895
|
|
2
|
+
python_osw_validation/extracted_data_validator.py,sha256=wZyCk8NlJv10cj_GrRTAiwm4cBhTAeDethjzJU-amoI,3877
|
|
3
|
+
python_osw_validation/version.py,sha256=k14HNX-j7JGQmMcNd5V9YYE1rd2NN5QFLz4W-ttaFD0,21
|
|
4
|
+
python_osw_validation/zipfile_handler.py,sha256=lCRraGcysxelVKswQw1r-i_9kGQGvRQk7hJkWUwiAPk,2692
|
|
5
|
+
python_osw_validation/schema/opensidewalks.schema.json,sha256=i0iJwb_4Tq20BVUpkpgyM_7fm4SW_d_HNXKw0xul7OA,240987
|
|
6
|
+
python_osw_validation-0.2.7.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
|
|
7
|
+
python_osw_validation-0.2.7.dist-info/METADATA,sha256=ZFW5vh8CHW1PU1WHpXtemdzhALazinWT79OaHNGCIDE,6117
|
|
8
|
+
python_osw_validation-0.2.7.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
|
9
|
+
python_osw_validation-0.2.7.dist-info/top_level.txt,sha256=GE81UPcDHEffJCxYu3M_iPz3Dt-O3axB73R5SLm_Veo,22
|
|
10
|
+
python_osw_validation-0.2.7.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
python_osw_validation/__init__.py,sha256=CToPu6up1oroUOG7sl15uNclhwTznBOGBRlpeN9q1Eo,7351
|
|
2
|
-
python_osw_validation/extracted_data_validator.py,sha256=1QFVVJRpkx8HfAWJmtJ2PxPBsD-UVsNk5I2VFzVJ5Ps,3333
|
|
3
|
-
python_osw_validation/version.py,sha256=G3YzB5xTyZTVDHgjxzwfUZHPQbqRjfJO_4NfpO-O5Lg,21
|
|
4
|
-
python_osw_validation/zipfile_handler.py,sha256=lCRraGcysxelVKswQw1r-i_9kGQGvRQk7hJkWUwiAPk,2692
|
|
5
|
-
python_osw_validation/schema/opensidewalks.schema.json,sha256=i0iJwb_4Tq20BVUpkpgyM_7fm4SW_d_HNXKw0xul7OA,240987
|
|
6
|
-
python_osw_validation-0.2.6.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
|
|
7
|
-
python_osw_validation-0.2.6.dist-info/METADATA,sha256=d7VByKt099S5QEjzVuT4K0Rveb1ZLNFi3Tn8MJXMsoc,6114
|
|
8
|
-
python_osw_validation-0.2.6.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
|
9
|
-
python_osw_validation-0.2.6.dist-info/top_level.txt,sha256=GE81UPcDHEffJCxYu3M_iPz3Dt-O3axB73R5SLm_Veo,22
|
|
10
|
-
python_osw_validation-0.2.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{python_osw_validation-0.2.6.dist-info → python_osw_validation-0.2.7.dist-info}/top_level.txt
RENAMED
|
File without changes
|