Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utilities to convert GPS trace file formats into SnapToRoads request #44

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

HabibaaElsherbiny
Copy link

Description of changes:

This PR adds utilities to convert different GPS trace file formats into SnapToRoads request JSON.

The following are the supported trace file formats as described in HERE's documentation:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@HabibaaElsherbiny HabibaaElsherbiny requested a review from a team as a code owner November 19, 2024 09:17
package.json Outdated Show resolved Hide resolved
src/from-csv/tracepoints-converter.ts Outdated Show resolved Hide resolved
src/from-csv/tracepoints-converter.ts Outdated Show resolved Hide resolved
src/from-geojson/tracepoints-converter.ts Outdated Show resolved Hide resolved
src/from-geojson/tracepoints-converter.ts Outdated Show resolved Hide resolved
src/from-geojson/tracepoints-converter.ts Show resolved Hide resolved
src/from-gpx/tracepoints-converter.test.ts Outdated Show resolved Hide resolved
Comment on lines +81 to +82
const xmlParser = new fastXmlParser.XMLParser(options);
const jsonObj = xmlParser.parse(content, options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/placemark/togeojson might be a worthwhile dependency to pick up, even if it goes to an intermediate format (GeoJSON), since it supports multiple file types (including KML, which would simplify that converter by sharing with this one).

Alternately, it probably makes sense to support its GeoJSON output in case customers use that dependency.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fastXmlParser also supports KML. Any reason why https://github.com/placemark/togeojson would be a better option?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fastXmlParser doesn't appear to be geo-aware and provides a lower-level API. togeojson contains higher-level conversion APIs that can replace the ones you've written using lower-level APIs.

src/from-nmea/tracepoints-converter.ts Outdated Show resolved Hide resolved
src/from-nmea/tracepoints-converter.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
src/from-csv/tracepoints-converter.ts Outdated Show resolved Hide resolved
src/from-csv/tracepoints-converter.ts Outdated Show resolved Hide resolved
src/from-csv/tracepoints-converter.ts Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
src/from-gpx/tracepoints-converter.test.ts Show resolved Hide resolved
src/from-kml/tracepoints-converter.ts Outdated Show resolved Hide resolved
src/from-nmea/tracepoints-converter.ts Outdated Show resolved Hide resolved
src/from-nmea/tracepoints-converter.test.ts Outdated Show resolved Hide resolved
mbalfour-amzn
mbalfour-amzn previously approved these changes Jan 10, 2025
src/from-csv/tracepoints-converter.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@mojodna mojodna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some minor suggestions.

2 bigger things though: 1) what's the story with the FP: prefix on encoded polylines? 2) what are your thoughts on using togeojson (the Placemark fork) to parse KML and GPX directly vs. implementing your own parsers?

src/from-csv/tracepoints-converter.ts Show resolved Hide resolved
*
* @param csvString - The input CSV string to be parsed.
* @param options - Optional configuration for parsing.
* @param options.columnMapping - Object mapping expected column names to actual CSV column names.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param options.columnMapping - Object mapping expected column names to actual CSV column names.
* @param options.columnMapping - Object mapping expected column names to actual CSV column names. This uses column names provided in the header row.

(We could also support CSVs without header rows by accepting an array with column names as columnNames or similar.)

[8.68752, 50.09878],
];
const encoded = encodeFromLngLatArray(input);
expect(flexiblePolylineStringToRoadSnapTracePointList(`FP:${encoded}`)).toEqual(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do our APIs require the FP: prefix? The API reference doesn't say anything about it, but that might be wrong.

src/from-geojson/tracepoints-converter.ts Show resolved Hide resolved
*
* Other properties that may be present in the input (such as provider, accuracy, and altitude) are ignored.
*
* Note: If multiple speed fields are provided, speed_kmh takes precedence.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be explicit about the full order in case speed_kmh is absent but the other 2 are present for whatever reason.

@@ -5,8 +5,21 @@ import * as fastXmlParser from "fast-xml-parser";
import { RoadSnapTracePoint } from "@aws-sdk/client-geo-routes";

/**
* It converts a GPX string to an array of RoadSnapTracePoint, so the result can be used to assemble the request to
* SnapToRoads API.
* It converts a GPX string with trkType to an array of RoadSnapTracePoint, so the result can be used to assemble the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"with trkType"? I kinda know what you're referring to, but I think we can be a bit more helpful.

Perhaps "a GPX string containing tracks..." with a link to https://en.wikipedia.org/wiki/GPS_Exchange_Format#Data_types to help people unfamiliar with the GPX format understand what XML elements are required to represent tracks.

src/from-gpx/tracepoints-converter.ts Show resolved Hide resolved
*
* - Coordinates (always present, used): Latitude and longitude in WGS84 degrees. Example: <trkpt lat="48.0289225"
* lon="-4.298227">
* - Timestamp (optional, used): In UTC time zone. Example: <time>2013-07-15T10:24:52Z</time>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have to be UTC? Would any ISO 8601-formatted timestamp suffice?

*
* - Contains a <Document> element with one or more <Placemark> elements.
* - Each <Placemark> has a <LineString> element with a <coordinates> child.
* - Coordinates are listed as a single string, separated by whitespace.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same as Well-Known Text (WKT)?

* Notes:
*
* - Altitude is ignored during parsing as it's not included in SnapToRoads API requests.
* - This function does not process KML timestamp or speed data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? (Not for the PR, but for discussion.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants