-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.js
57 lines (53 loc) · 1.9 KB
/
filter.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
import * as fs from "fs";
import * as readline from "readline";
function include(tags) {
// From https://flrec.ifas.ufl.edu/geomatics/hochmair/pubs/hochmair_zielstra_neis_TRB2013.pdf
// Used regex to transform the SQL query into JS...
// s/=/==/g14
// s/AND/\&\&/g14
// s/OR /|| /g14
// s#(tags->'\([^']*\)')#tags\["\1\"\]#g14
return (
(tags["highway"] == "track" &&
tags["bicycle"] == "designated" &&
tags["motor_vehicle"] == "no") ||
(tags["highway"] == "path" && tags["bicycle"] == "yes") ||
(tags["highway"] == "path" &&
(tags["bicycle"] == "designated" || tags["bicycle"] == "official")) ||
(tags["highway"] == "service" &&
tags["bicycle"] == "designated" &&
tags["motor_vehicle"] == "no") ||
(tags["highway"] == "pedestrian" &&
(tags["bicycle"] == "yes" || tags["bicycle"] == "official")) ||
(tags["highway"] == "footway" &&
(tags["bicycle"] == "yes" || tags["bicycle"] == "official")) ||
tags["highway"] == "cycleway" ||
(tags["highway"] == "bridleway" && tags["bicycle"] != "no") ||
tags["cycleway"] == "track" ||
tags["cycleway"] == "opposite_track" ||
tags["cycleway"] == "lane" ||
tags["cycleway:left"] == "lane" ||
tags["cycleway:right"] == "lane" ||
tags["cycleway:both"] == "lane" ||
tags["cycleway"] == "opposite_lane" ||
tags["cycleway"] == "shared_busway" ||
tags["cycleway:left"] == "shared_busway" ||
tags["cycleway:right"] == "shared_busway"
);
}
console.error(`{"type": "FeatureCollection", "features": [`);
let rl = readline.createInterface({
input: fs.createReadStream(process.argv[2]),
});
rl.on("line", (line) => {
let f = JSON.parse(line);
if (include(f.properties)) {
// Clear properties for smaller output
let osm_id = f.properties["@id"];
f.properties = {osm_id};
console.error(JSON.stringify(f) + ",");
}
});
rl.on("close", () => {
console.error(`]}`);
});