Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 36 additions & 22 deletions gpx/api/gpx.api

Large diffs are not rendered by default.

42 changes: 30 additions & 12 deletions gpx/api/gpx.klib.api

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions gpx/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ kotlin {
}
}

// ElementSerializer doesn't work in NodeJS because DOMParser is only available in browser
// https://github.com/pdvrieze/xmlutil/issues/298
tasks.named("jsNodeTest") { enabled = false }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could polyfill DOMParser on node like

import { DOMParser } from 'xmldom';
global.DOMParser = DOMParser;

But I failed to get that set up. Maybe another time


mavenPublishing {
pom {
name = "Spatial K GPX"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Required
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import nl.adaptivity.xmlutil.dom2.Element
import nl.adaptivity.xmlutil.serialization.XmlElement
import nl.adaptivity.xmlutil.serialization.XmlSerialName
import org.maplibre.spatialk.gpx.serializers.UtcDefaultInstantSerializer
Expand All @@ -27,6 +28,7 @@ import org.maplibre.spatialk.gpx.serializers.UtcDefaultInstantSerializer
* @property waypoints A list of waypoints.
* @property routes A list of routes.
* @property tracks A list of tracks.
* @property extensions Extension schema elements.
*/
@XmlSerialName("gpx", "http://www.topografix.com/GPX/1/1")
@OptIn(ExperimentalSerializationApi::class)
Expand All @@ -45,6 +47,7 @@ public data class Document(
@XmlSerialName("wpt")
@XmlElement
val waypoints: List<Waypoint> = listOf(),
@XmlSerialName("extensions") @XmlElement val extensions: Element? = null,
)

/**
Expand All @@ -62,6 +65,7 @@ public data class Document(
* @property keywords Keywords associated with the file. Search engines or databases may use them.
* @property bounds The minimum and maximum coordinates that describe the extent of the data in the
* file.
* @property extensions Extension schema elements.
*/
@Serializable
public data class Metadata
Expand All @@ -78,7 +82,7 @@ constructor(
val timestamp: Instant? = null,
@XmlElement val keywords: String? = null,
@XmlSerialName("bounds") @XmlElement val bounds: Bounds? = null,
// val extensions: Extensions?,
@XmlSerialName("extensions") @XmlElement val extensions: Element? = null,
)

/**
Expand Down
4 changes: 3 additions & 1 deletion gpx/src/commonMain/kotlin/org/maplibre/spatialk/gpx/Route.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.maplibre.spatialk.gpx

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import nl.adaptivity.xmlutil.dom2.Element
import nl.adaptivity.xmlutil.serialization.XmlElement
import nl.adaptivity.xmlutil.serialization.XmlSerialName
import org.maplibre.spatialk.geojson.Feature
Expand All @@ -25,6 +26,7 @@ import org.maplibre.spatialk.geojson.Point
* (e.g., "resupply", "scenic").
* @property points A list of route points ([Waypoint]) which are the turning points, intersections,
* or other critical points in the route.
* @property extensions Extension schema elements.
*/
@Serializable
public data class Route(
Expand All @@ -36,7 +38,7 @@ public data class Route(
@SerialName("number") @XmlElement val number: Int?,
@SerialName("type") @XmlElement val type: String?,
@SerialName("rtept") @XmlSerialName("rtept") @XmlElement val points: List<Waypoint>,
// @XmlElement val extensions = null,
@XmlSerialName("extensions") @XmlElement val extensions: Element? = null,
)

/**
Expand Down
9 changes: 6 additions & 3 deletions gpx/src/commonMain/kotlin/org/maplibre/spatialk/gpx/Track.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.maplibre.spatialk.gpx

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import nl.adaptivity.xmlutil.dom2.Element
import nl.adaptivity.xmlutil.serialization.XmlElement
import nl.adaptivity.xmlutil.serialization.XmlSerialName
import org.maplibre.spatialk.geojson.Feature
Expand All @@ -23,6 +24,7 @@ import org.maplibre.spatialk.geojson.Point
* @property number A GPS track number.
* @property type The type of activity for the track (e.g., "cycling", "running").
* @property segments A list of track segments that make up the track.
* @property extensions Extension schema elements.
*/
@Serializable
public data class Track(
Expand All @@ -37,7 +39,7 @@ public data class Track(
@XmlSerialName("trkseg")
@XmlElement
val segments: List<TrackSegment> = listOf(),
// @XmlElement val extensions = null,
@XmlSerialName("extensions") @XmlElement val extensions: Element? = null,
)

/**
Expand Down Expand Up @@ -69,11 +71,12 @@ public fun Track.toGeoJson(): Feature<GeometryCollection<Point>, Track> {
* See [trksegType](https://www.topografix.com/GPX/1/1/#type_trksegType).
*
* @property points A list of track points.
* @property extensions Extension schema elements.
*/
@Serializable
public data class TrackSegment(
@XmlSerialName("trkpt") @XmlElement val points: List<Waypoint>
// @XmlElement val extensions = null,
@XmlSerialName("trkpt") @XmlElement val points: List<Waypoint>,
@XmlSerialName("extensions") @XmlElement val extensions: Element? = null,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlin.time.ExperimentalTime
import kotlin.time.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import nl.adaptivity.xmlutil.dom2.Element
import nl.adaptivity.xmlutil.serialization.XmlElement
import nl.adaptivity.xmlutil.serialization.XmlSerialName
import org.maplibre.spatialk.geojson.Feature
Expand Down Expand Up @@ -42,6 +43,7 @@ import org.maplibre.spatialk.gpx.serializers.UtcDefaultInstantSerializer
* @property positionDop Position dilution of precision.
* @property dgpsAge Number of seconds since last DGPS update.
* @property dgpsId ID of DGPS station used in differential correction.
* @property extensions Extension schema elements.
*/
@Serializable
@OptIn(ExperimentalTime::class)
Expand Down Expand Up @@ -69,7 +71,7 @@ public data class Waypoint(
@SerialName("pdop") @XmlElement val positionDop: Double? = null,
@SerialName("ageofdgpsdata") @XmlElement val dgpsAge: Double? = null,
@SerialName("dgpsid") @XmlElement val dgpsId: Double? = null,
// @XmlElement val extensions = null,
@XmlSerialName("extensions") @XmlElement val extensions: Element? = null,
)

/**
Expand Down
27 changes: 14 additions & 13 deletions gpx/src/commonTest/resources/in/track.gpx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1" creator="ChatGPT-GPX" xmlns="http://www.topografix.com/GPX/1/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd">
http://www.topografix.com/GPX/1/1/gpx.xsd"
xmlns:gpxtpx="https://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd">

<metadata>
<name>Sample Track</name>
Expand Down Expand Up @@ -36,31 +37,37 @@
<trkpt lat="37.7749" lon="-122.4194">
<ele>15.2</ele>
<time>2025-10-22T12:00:00Z</time>
<course>90.0</course>
<speed>1.4</speed>
<magvar>12.5</magvar>
<geoidheight>-29.0</geoidheight>
<sat>10</sat>
<hdop>0.9</hdop>
<vdop>1.2</vdop>
<pdop>1.6</pdop>
<fix>3d</fix>
<extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:hr>156</gpxtpx:hr>
<gpxtpx:cad>90</gpxtpx:cad>
</gpxtpx:TrackPointExtension>
</extensions>
</trkpt>

<trkpt lat="37.7765" lon="-122.4290">
<ele>22.8</ele>
<time>2025-10-22T12:05:00Z</time>
<course>92.0</course>
<speed>1.6</speed>
<fix>3d</fix>
<sat>9</sat>
<extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:hr>156</gpxtpx:hr>
<gpxtpx:cad>90</gpxtpx:cad>
</gpxtpx:TrackPointExtension>
</extensions>
</trkpt>

<trkpt lat="37.7780" lon="-122.4410">
<ele>35.6</ele>
<time>2025-10-22T12:10:00Z</time>
<course>100.0</course>
<speed>1.8</speed>
<fix>3d</fix>
<sat>8</sat>
</trkpt>
Expand All @@ -70,26 +77,20 @@
<trkpt lat="37.7694" lon="-122.4862">
<ele>48.3</ele>
<time>2025-10-22T12:20:00Z</time>
<course>110.0</course>
<speed>2.0</speed>
<fix>dgps</fix>
<sat>9</sat>
</trkpt>

<trkpt lat="37.7790" lon="-122.4600">
<ele>62.7</ele>
<time>2025-10-22T12:30:00Z</time>
<course>120.0</course>
<speed>2.2</speed>
<fix>3d</fix>
<sat>10</sat>
</trkpt>

<trkpt lat="37.8021" lon="-122.4488">
<ele>90.4</ele>
<time>2025-10-22T12:45:00Z</time>
<course>135.0</course>
<speed>0.0</speed>
<fix>3d</fix>
<sat>12</sat>
</trkpt>
Expand Down
13 changes: 13 additions & 0 deletions gpx/src/commonTest/resources/in/track_lenient.gpx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* unknown metadata element
-->
<gpx version="1.1" xmlns="http://www.topografix.com/GPX/1/1"
xmlns:gpxtpx="https://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata>
<name>Sample Track</name>
Expand Down Expand Up @@ -50,6 +51,12 @@
<vdop>1.2</vdop>
<pdop>1.6</pdop>
<fix>3d</fix>
<extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:hr>156</gpxtpx:hr>
<gpxtpx:cad>90</gpxtpx:cad>
</gpxtpx:TrackPointExtension>
</extensions>
</trkpt>

<trkpt lat="37.7765" lon="-122.4290">
Expand All @@ -59,6 +66,12 @@
<speed>1.6</speed>
<fix>3d</fix>
<sat>9</sat>
<extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:hr>156</gpxtpx:hr>
<gpxtpx:cad>90</gpxtpx:cad>
</gpxtpx:TrackPointExtension>
</extensions>
</trkpt>

<trkpt lat="37.7780" lon="-122.4410">
Expand Down
14 changes: 14 additions & 0 deletions gpx/src/commonTest/resources/out/track.gpx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,26 @@
<hdop>0.9</hdop>
<vdop>1.2</vdop>
<pdop>1.6</pdop>
<extensions>
<gpxtpx:TrackPointExtension
xmlns:gpxtpx="https://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd">
<gpxtpx:hr>156</gpxtpx:hr>
<gpxtpx:cad>90</gpxtpx:cad>
</gpxtpx:TrackPointExtension>
</extensions>
</trkpt>
<trkpt lat="37.7765" lon="-122.429">
<ele>22.8</ele>
<time>2025-10-22T12:05:00Z</time>
<fix>3d</fix>
<sat>9</sat>
<extensions>
<gpxtpx:TrackPointExtension
xmlns:gpxtpx="https://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd">
<gpxtpx:hr>156</gpxtpx:hr>
<gpxtpx:cad>90</gpxtpx:cad>
</gpxtpx:TrackPointExtension>
</extensions>
</trkpt>
<trkpt lat="37.778" lon="-122.441">
<ele>35.6</ele>
Expand Down