Skip to content

Commit

Permalink
Script to generate routlines from geojson
Browse files Browse the repository at this point in the history
  • Loading branch information
seadeep42 committed Oct 19, 2024
1 parent 858ef07 commit ef5714f
Show file tree
Hide file tree
Showing 50 changed files with 282,973 additions and 120 deletions.
30 changes: 30 additions & 0 deletions scripts/get_routelines.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Read files in the routeline_data folder and write them to the src/utils/routelines.json file
*/

import fs from "node:fs";
import path from "node:path";
import _ from "lodash";
import polyline from "google-polyline";

const routelineDataFolder = path.join(process.cwd(), "routeline_data");
const routelineDataFiles = fs.readdirSync(routelineDataFolder);

const routelines = {};

for (const file of routelineDataFiles) {
const filePath = path.join(routelineDataFolder, file);
const routelineData = JSON.parse(fs.readFileSync(filePath, "utf8"));
const routename = path.basename(file, ".geojson");
const encodedRouteline = encodeURIComponent(
polyline.encode(
routelineData.features[0].geometry.coordinates
),
);
routelines[routename] = encodedRouteline;
}

fs.writeFileSync(
path.join(process.cwd(), "..", "src", "utils", "routelines.json"),
JSON.stringify(routelines, null, 2),
);
Loading

0 comments on commit ef5714f

Please sign in to comment.