This repository was archived by the owner on Mar 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildDistinctStreets.js
More file actions
53 lines (53 loc) · 1.93 KB
/
buildDistinctStreets.js
File metadata and controls
53 lines (53 loc) · 1.93 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
import * as fs from "fs";
import { parse as jsonToCSV } from "json2csv";
;
console.log("Loading streets.json");
const streets = JSON.parse(fs.readFileSync("data/streets.json"));
const distinctStreetsMap = new Map();
for (const street of streets) {
if (street.MUNICIPALITY !== "Sault Ste. Marie") {
continue;
}
const mapKey = street.MUNICIPALITY + "::" + street.FULLNAME;
if (distinctStreetsMap.has(mapKey)) {
const distinctStreet = distinctStreetsMap.get(mapKey);
distinctStreet.LEFTFROMADDRESS = Math.min(distinctStreet.LEFTFROMADDRESS, street.LEFTFROMADDRESS);
distinctStreet.LEFTTOADDRESS = Math.max(distinctStreet.LEFTTOADDRESS, street.LEFTTOADDRESS);
distinctStreet.RIGHTFROMADDRESS = Math.min(distinctStreet.RIGHTFROMADDRESS, street.RIGHTFROMADDRESS);
distinctStreet.RIGHTTOADDRESS = Math.max(distinctStreet.RIGHTTOADDRESS, street.RIGHTTOADDRESS);
}
else {
distinctStreetsMap.set(mapKey, {
FULLNAME: street.FULLNAME,
STREETPREFIX: street.STREETPREFIX,
STREETNAME: street.STREETNAME,
STREETTYPE: street.STREETTYPE,
STREETSUFFIX: street.STREETSUFFIX,
LEFTFROMADDRESS: street.LEFTFROMADDRESS,
LEFTTOADDRESS: street.LEFTTOADDRESS,
RIGHTFROMADDRESS: street.RIGHTFROMADDRESS,
RIGHTTOADDRESS: street.RIGHTTOADDRESS,
MUNICIPALITY: street.MUNICIPALITY
});
}
}
const distinctStreets = Array.from(distinctStreetsMap.values());
distinctStreets.sort((streetA, streetB) => {
if (streetA.FULLNAME > streetB.FULLNAME) {
return 1;
}
return -1;
});
try {
fs.writeFileSync("./data/streets-distinct.json", JSON.stringify(distinctStreets, null, " "));
}
catch (error) {
console.error(error);
}
const csvData = jsonToCSV(distinctStreets);
try {
fs.writeFileSync("./data/streets-distinct.csv", csvData);
}
catch (error) {
console.error(error);
}