-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script to generate routlines from geojson
- Loading branch information
Showing
50 changed files
with
282,973 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
); |
Oops, something went wrong.