@mikaello/gpxfaketimer
v0.1.0
Published
Create (or modify) timestamps in a GPX file
Readme
GPX fake timer
Create timestamps for every trackpoint in a GPX file.
npm install @mikaello/gpxfaketimerExample
import { createTimestampsEvenly } from "@mikaello/gpxfaketimer";
const exampleGpx = `
<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.0">
<name>Example gpx</name>
<trk>
<name>Example gpx</name>
<number>1</number>
<trkseg>
<trkpt lat="46.57608333" lon="8.89241667">
<ele>2376</ele>
</trkpt>
<trkpt lat="46.57619444" lon="8.89252778">
<ele>2375</ele>
</trkpt>
<trkpt lat="46.57661111" lon="8.89344444">
<ele>2376</ele>
</trkpt>
</trkseg>
</trk>
</gpx>
`;
console.log(createTimestampsEvenly(exampleGpx, 0, 100000));
// => will return the same GPX file, only with <time>date here</time> inside every trkpt:
/*
<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.0">
<name>Example gpx</name>
<trk>
<name>Example gpx</name>
<number>1</number>
<trkseg>
<trkpt lat="46.57608333" lon="8.89241667">
<ele>2376</ele>
<time>1970-01-01T00:00:00.000Z</time>
</trkpt>
<trkpt lat="46.57619444" lon="8.89252778">
<ele>2375</ele>
<time>1970-01-01T00:00:50.000Z</time>
</trkpt>
<trkpt lat="46.57661111" lon="8.89344444">
<ele>2376</ele>
<time>1970-01-01T00:01:40.000Z</time>
</trkpt>
</trkseg>
</trk>
</gpx>
*/API
createTimestampsEvenly(gpxContent: string, startTime: number, endTime: number) => string: returns the incominggpxContentenriched with timestamps in everytrkptelement.startTimeandendTimeare milliseconds since epoch.createTimestampsFromSpeed(gpxContent: string, startTime: number, speed: number, unit?: "kmh" | "mph") => string: returns the incominggpxContentenriched with timestamps calculated from the GPS distance between each track point at the given speed.unitdefaults to"kmh".
CLI
npx @mikaello/gpxfaketimer input.gpx --output output.gpxOptions:
| Flag | Description |
|------|-------------|
| --output, -o | Output file (default: stdout) |
| --start | Start time as ISO 8601 or Unix ms (default: now) |
| --end | End time for evenly distributed mode |
| --speed | Speed value for distance-based timing |
| --unit | Speed unit: kmh or mph (default: kmh, requires --speed) |
| --help, -h | Show help |
When --speed is provided, timestamps are calculated from GPS distances at that
speed.
Otherwise, timestamps are evenly distributed between --start and --end
(default duration: 1 hour).
Utility functions
Not specific for GPX, but just as helper functions
getUniformDistribution(count: number, intervalStart: number, intervalEnd: number) => number[]:
returns an array of length count with first element intervalStart and last
element intervalEnd, all elements in between is evenly distributed between
these extremeties.
Develop
You can use the ./example project to ease developing. Run
npm run dev from that folder to start a Vite dev server that loads the code
from this module with hot module replacement.
Contributions are welcome :-)
