Installation
Install the plugin using npm:Configuration & Parameters
The plugin is configured with an object containing the following properties, which map to field slugs in your Sheet:Required Parameters
- sheetSlug (
string
): The slug of the sheet the plugin should operate on. - gpxFileField (
string
): The field slug in the source record that contains the GPX file content as a string.
Optional Parameters
- removeDuplicatesField (
string
): The field slug that acts as a boolean flag. If the value in this field for a given record is the string “true”, duplicate points will be removed from the parsed data. - filterDatesField (
string
): The field slug that acts as a boolean flag. If the value in this field for a given record is the string “true”, the parsed data will be filtered by a date range. - startDateField (
string
): The field slug containing the start date for filtering. This is only used iffilterDatesField
is set to “true”. The value should be a valid date string. - endDateField (
string
): The field slug containing the end date for filtering. This is only used iffilterDatesField
is set to “true”. The value should be a valid date string.
Default Behavior
By default, the plugin will parse the GPX file without removing duplicates or filtering by date. These processing steps are only activated if the corresponding fields (removeDuplicatesField
, filterDatesField
) in the record are explicitly set to the string “true”. If filtering is enabled but the start or end date fields are empty or invalid, the date filter will not be applied.
Usage Examples
Basic Setup
Complete Configuration Example
Using Utility Functions
The plugin exports several utility functions that can be used independently for custom data processing tasks:API Reference
enrichGpx(listener, config)
The main plugin entry point that configures and attaches a record hook to a Flatfile listener. Parameters:listener
: FlatfileListener - The Flatfile listener instance to attach the hook toconfig
: GpxParserConfig - Configuration object containing field mappings
calculateDistance(point1, point2)
Calculates the great-circle distance between two geographical points using the Haversine formula. Parameters:point1
: Waypoint - Object withlatitude
andlongitude
propertiespoint2
: Waypoint - Object withlatitude
andlongitude
properties
removeDuplicatePoints(points)
Removes duplicate waypoints from an array based on latitude, longitude, elevation, and time. Parameters:points
: Waypoint[] - Array of waypoint objects
filterByDateRange(points, startDate, endDate)
Filters waypoints to include only those within a specified date range. Parameters:points
: Waypoint[] - Array of waypoint objects with optionaltime
propertystartDate
: Date - Start of the date rangeendDate
: Date - End of the date range
calculateStatistics(tabularData)
Calculates total distance and cumulative positive elevation gain for a path of waypoints. Parameters:tabularData
: Waypoint[] - Sorted array of waypoint objects
totalDistance
(km) and elevationGain
(meters) properties
convertToTabularFormat(waypoints, tracks, routes)
Merges separate arrays of waypoints, tracks, and routes into a single, flat array sorted by time. Parameters:waypoints
: Waypoint[] - Array of waypoint objectstracks
: Track[] - Array of track objectsroutes
: Route[] - Array of route objects
Troubleshooting
Common Issues
- Data not processing: Ensure the
sheetSlug
in the configuration exactly matches the slug of your target Sheet - Field mapping errors: Verify that all field slugs in the configuration match the field keys in your Sheet template
- Invalid GPX content: Check that the
gpxFileField
contains valid GPX XML content - Date filtering not working: Ensure the
filterDatesField
contains the string “true” and that date fields contain valid date strings
Error Handling
The plugin includes comprehensive error handling:- Missing GPX content: Adds error message ‘GPX file content is required’ to the
gpxFileField
- Invalid XML: Adds generic error message ‘Failed to parse GPX content’ to the
gpxFileField
- Processing continues: Records are always returned to ensure other records can be processed
Notes
Important Considerations
- The plugin operates on the
commit:created
event using arecordHook
- GPX data must be provided as a complete XML string within the specified field
- Boolean-like options are controlled by the string value “true”, not native boolean types
- The plugin will overwrite values in target fields with extracted GPX data
- Processing steps (deduplication, date filtering) are only activated when explicitly enabled
Limitations
- Does not handle file uploads directly, only processes string content from uploads
- Requires valid GPX XML format for successful parsing
- Date filtering requires valid date strings in the specified format