forked from GauChoob/bs-cartography
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate_json.js
72 lines (67 loc) · 2.2 KB
/
validate_json.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const geojson = require('./geojson/index.js')
const episode_properties = [
'name',
'category',
]
const room_properties = [
'name',
'category',
//'color',
//'summary',
'episode',
]
const validate_polygon = feature => {
if(feature.geometry.type !== 'Polygon') {
console.log(`${feature.properties.name} invalid geometry type (not polygon)`)
return
}
const coordinates = feature.geometry.coordinates
if(coordinates.length !== 1) {
console.log(`${feature.properties.name} multi-polygonal`)
}
const polygon = coordinates[0]
if(polygon[0][0] !== polygon[polygon.length - 1][0] || polygon[0][1] !== polygon[polygon.length - 1][1]) {
console.log(`${feature.properties.name} first and last coordinates are not identical`)
}
}
// TODO: validate polygons as closed loops
console.log('Checking Episodes')
const episode_names = new Set()
for(const episode of geojson.episodes.features) {
validate_polygon(episode)
if(episode.properties.category !== 'Episode') {
console.log(`${episode.properties.name} invalid category`)
}
if('id' in episode) {
console.log(`${episode.properties.name} has id`)
}
if(episode_names.has(episode.properties.name)) {
console.log(`${episode.properties.name} duplicate name!`)
}
episode_names.add(episode.properties.name)
for(const property of episode_properties) {
if(!(property in episode.properties)) {
console.log(`${episode.properties.name} missing property ${property}`)
}
}
}
console.log('Checking Rooms')
const room_names = new Set()
for(const room of geojson.rooms.features) {
validate_polygon(room)
if(room.properties.category !== 'Room') {
console.log(`${room.properties.name} invalid category`)
}
if('id' in room) {
console.log(`${room.properties.name} has id`)
}
if(room_names.has(room.properties.name)) {
console.log(`${room.properties.name} duplicate name!`)
}
room_names.add(room.properties.name)
for(const property of room_properties) {
if(!(property in room.properties)) {
console.log(`${room.properties.name} missing property ${property}`)
}
}
}