Skip to content

Commit 5586669

Browse files
committed
[wip] recatching the code. need tests.
1 parent 45ebefe commit 5586669

4 files changed

Lines changed: 90 additions & 25 deletions

File tree

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1-
# package_validator
2-
PLANMAP packages validation framework
1+
# PLANMAP package validator
2+
3+
This tool validates the structure and content of a Planmap package.
4+
5+
The validator gets as input the path to a (PM) package and then
6+
run a series of checks following a package/data model.
7+
8+
## To run the validator
9+
10+
```bash
11+
$ python validate.py <path>
12+
```
13+
14+
## Where are the models
15+
16+
## How to modify the models

some_schema_for_Units.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
4+
"title": "Match Geopackage's 'Units' layer columns list",
5+
6+
"$comment": "Works for, e.g., ['name','geometry','code','bla'], but not for ['bla','name','geometry','code']",
7+
"$example": ["name","geometry","code","another-column"],
8+
9+
"definitions": {
10+
11+
"point_coordinates": {
12+
"type": "array",
13+
"items": [
14+
{
15+
"type": "number"
16+
}
17+
],
18+
"minItems": 2,
19+
"maxItems": 3
20+
},
21+
22+
"line_coordinates": {
23+
"type": "array",
24+
"items": [
25+
{
26+
"$ref": "#/definitions/point_coordinates"
27+
}
28+
],
29+
"minItems": 2
30+
},
31+
32+
"polygon_coordinates": {
33+
"type": "array",
34+
"items": [
35+
{
36+
"$ref": "#/definitions/line_coordinates"
37+
},
38+
{ "minItems": 4 }
39+
]
40+
},
41+
42+
"polygon": {
43+
"type": "object",
44+
"properties": {
45+
"coordinates": {
46+
"$ref": "#/definitions/polygon_coordinates"
47+
}
48+
}
49+
}
50+
},
51+
52+
"type": "object",
53+
"properties": {
54+
"geometry": {
55+
"$ref": "#/definitions/polygon"
56+
}
57+
}
58+
}

validate.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@
1111
from itertools import zip_longest
1212

1313

14-
# _here = os.path.abspath(__file__)
15-
# sys.path.insert(0, _here)
16-
#
17-
# from validator import Validator
18-
#
19-
# config = {
20-
# 'geo_path': 'tmp/PM-MAR-MS-Arsinoes_01/vector/PM-MAR-MS-Arsinoes_01.gpkg',
21-
# 'geopackage_tables': ['units', 'contacts']
22-
# }
2314
import check
2415

2516
import logging
@@ -75,28 +66,30 @@ def check_raster(pkg_specs, pkg_path):
7566
def check_model(pkg_specs, pkg_path):
7667
pass
7768

78-
def run(pkg_path):
79-
#parse package name
80-
pkg_name = os.path.basename(os.path.abspath(pkg_path))
81-
logger.debug(f"Package name: {pkg_name}")
82-
pkg_specs = parse_package_name(pkg_name)
83-
pkg_specs['name'] = pkg_name
84-
logger.info(pkg_specs)
69+
def run(geopackage):
70+
from .validator import vector
8571

8672
# Check geopackage
87-
out = check_vector(pkg_specs, pkg_path)
73+
out = vector.check(geopackage)
8874

8975

9076
if __name__ == '__main__':
9177
from argparse import ArgumentParser
9278

9379
parser = ArgumentParser()
94-
parser.add_argument('path', type=str,
95-
help="Path of PlanMap package")
80+
parser.add_argument('fname', type=str,
81+
help="Path of GeoPackage")
82+
parser.add_argument('--vector', default=False, action_store=True,
83+
help="Verifies a vector data file (GeoPackage)")
84+
parser.add_argument('--schema', type=str,
85+
help="File with metadata structure to use as model")
9686

9787
args = parser.parse_args()
98-
pkg_path = args.path
88+
if not args.vector:
89+
print("Implemented for vectors only")
90+
sys.exit(1)
9991

100-
# res = run(args.cfg, args.log)
92+
fname = args.fname
93+
schema = args.schema
10194

102-
res = run(pkg_path)
95+
res = run(fname)

validator/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .validator import Validator
1+
# from .validator import Validator

0 commit comments

Comments
 (0)