-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04validate.js
45 lines (37 loc) · 1.34 KB
/
04validate.js
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
import fs from 'fs'
import sqlite3 from 'sqlite3'
// gpkg files are not automatically downloaded
// you will find the links in sources/adjusted
// then put the files directly in sources/gpkg
fs.readJsonSync = path => JSON.parse(fs.readFileSync(path))
const folderPath = 'out'
const { sources } = fs.readJsonSync('sources.json')
// choose file you want to validate
let i = 6
let source = sources[i]
let metadata = fs.readJsonSync('sources/adjusted/' + source.split('/').at(-1) + '.json')
let outPath = folderPath + '/' + metadata.desc.split('/').at(-1).slice(0, -4) + '.json'
let desc = fs.readJsonSync(outPath)
let gpkg = metadata.gpkg.split('/').at(-1)
let db = new sqlite3.Database('sources/gpkg/' + gpkg, err => {
if (err) return console.error(err.message)
console.log('Connected to db')
desc.layers.forEach(layer => {
let rows = []
db.each(`pragma table_info('${layer.layer}')`, (err, row) => {
if (err) return console.error(err.message)
rows.push(row)
}, () => {
let names = rows.map(row => row.name)
let errors = 0
layer.columns.forEach(column => {
if (!names.includes(column.column)) {
errors++
console.warn('column', column.column, 'in layer', layer.layer, 'missing')
}
})
if (!errors) console.log('no errors in layer', layer.layer)
})
})
db.close()
})