Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 Down Expand Up @@ -45,6 +46,7 @@ public data class Document(
@XmlSerialName("wpt")
@XmlElement
val waypoints: List<Waypoint> = listOf(),
@XmlSerialName("extensions") @XmlElement val extensions: Element? = null,
)

/**
Expand Down Expand Up @@ -78,7 +80,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
3 changes: 2 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 Down Expand Up @@ -36,7 +37,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
7 changes: 4 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 Down Expand Up @@ -37,7 +38,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 @@ -72,8 +73,8 @@ public fun Track.toGeoJson(): Feature<GeometryCollection<Point>, Track> {
*/
@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 @@ -69,7 +70,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="http://www.garmin.com/xmlschemas/TrackPointExtension/v1">

<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="http://www.garmin.com/xmlschemas/TrackPointExtension/v1"
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="http://www.garmin.com/xmlschemas/TrackPointExtension/v1">
<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="http://www.garmin.com/xmlschemas/TrackPointExtension/v1">
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

xmlutil quirk: namespace declarations are added to each element instead of the root only. There is a isCollectingNSAttributes config option to configure this, but it does not seem to work for dynamic namespaces in Elements

<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
Loading