-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbicycleinfrastructure.js
More file actions
74 lines (67 loc) · 2.8 KB
/
bicycleinfrastructure.js
File metadata and controls
74 lines (67 loc) · 2.8 KB
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
73
74
import fetch from "node-fetch";
import osmtogeojson from "osmtogeojson";
import { writeFile } from "fs";
import { ENDPOINT_BI } from "./bicycleinfrastructureHelpers/overpassQueryBI.js";
import { ENDPOINT_NW } from "./bicycleinfrastructureHelpers/overpassQueryNW.js";
import { ENDPOINT_AA } from "./bicycleinfrastructureHelpers/overpassQueryAA.js";
import {
addAttributes,
addBikeInfrastructureType,
aggregateBiAdminArea,
appendNWtoBI,
duplicatePolygonsToPoints,
duplicateTrafficCalming,
splitTrafficSignalLines,
} from "./bicycleinfrastructureHelpers/helperFunctions.js";
async function getOSM(ENDPOINT_BI, ENDPOINT_NW, ENDPOINT_AA) {
// appraoch API for Bicycle Infrastructure (BI) Data
console.log("start API-Request BI data...");
let responseBi = await fetch(ENDPOINT_BI);
let dataBi = await responseBi.json();
console.log("finished API-Request BI data...");
console.log("start preprocessing BI data...");
let geojsonBi = osmtogeojson(dataBi);
// categorize data by BI types
let geojsonBiType = addBikeInfrastructureType(geojsonBi);
// duplicate Polygons to Points
geojsonBiType = duplicatePolygonsToPoints(geojsonBiType);
// duplicate overwritten traffic calmed ways
geojsonBiType = duplicateTrafficCalming(geojsonBiType);
// split Traffic Signal LineStrings
geojsonBiType = splitTrafficSignalLines(geojsonBiType);
// add attributes for every Feature
geojsonBiType = addAttributes(geojsonBiType);
console.log("finished preprocessing BI data...");
// appraoch API for Network (NW) Data
console.log("start API-Request NW data...");
let responseNw = await fetch(ENDPOINT_NW);
let dataNw = await responseNw.json();
console.log("finished API-Request NW data...");
// append NW data to BI data
console.log("start preprocessing NW data...");
let geojsonNw = osmtogeojson(dataNw);
geojsonBiType = appendNWtoBI(geojsonNw, geojsonBiType);
console.log("finished preprocessing NW data...");
// approach Overpass-API for Administrative Area (AA) Data
console.log("start API-Request AA data...");
let responseAa = await fetch(ENDPOINT_AA);
let dataAa = await responseAa.json();
console.log("finish API-Request AA data");
// preprocessing AA
console.log("start preprocessing AA data...");
let geojsonAa = osmtogeojson(dataAa);
console.log("Calculate parking, cycling, service data for admin areas...");
geojsonBiType = aggregateBiAdminArea(geojsonAa, geojsonBiType);
console.log("Calculation completed!");
// write data to GeoJSON file
const geojsonBiTypeString = JSON.stringify(geojsonBiType);
writeFile("./bicycleinfrastructure.geojson", geojsonBiTypeString, (err) => {
if (err) {
console.log("Error writing file", err);
} else {
console.log("Successfully wrote file");
}
});
}
// Execute Function
getOSM(ENDPOINT_BI, ENDPOINT_NW, ENDPOINT_AA);