Skip to content

Colota - Android GPS Location tracker

feat(export): columnar MultiPoint GeoJSON export (#515)

Max Dietrich5b80e2b536d1
diff --git a/apps/docs/docs/development/architecture.md b/apps/docs/docs/development/architecture.md
index ee69a03a..a65915ac 100644
--- a/apps/docs/docs/development/architecture.md
+++ b/apps/docs/docs/development/architecture.md
@@ -123,7 +123,7 @@ Native-only modules in the `importer/` package. Format-specific parsers all retu
| Module | Purpose |
| --- | --- |
| `LocationImporter` | Orchestrator. Detects format from the sniff (XML root for GPX/KML, JSON top-level keys for GeoJSON / Google Timeline, CSV header for CSV), dispatches to the per-format parser, runs streaming **merge-walk dedup** against an ASC-ordered DB cursor (no existing-key `HashSet` is materialised - memory is O(1) on top of the parsed-rows list, so the dedup scales to multi-million-row user histories without OOM). On commit, the recovery path writes `sent = 1` and skips the queue; the migration path (`asQueued=true`) builds payloads via the live `PayloadBuilder` against a synthetic `android.location.Location` so the import path can't drift from the live tracking path. |
-| `GeoJsonParser` | Streaming `android.util.JsonReader`-based parser for `FeatureCollection` of `Point` features. Tolerates foreign shapes - any feature without a recognised time / non-Point geometry is counted as invalid and dropped, but parsing continues. |
+| `GeoJsonParser` | Streaming `android.util.JsonReader`-based parser for a `FeatureCollection` of `Point` features (scalar properties) or Colota's columnar `MultiPoint` features (per-point attributes as parallel arrays, including `note` / `battery_status`), zipped by index. Tolerates foreign shapes - any feature without a recognised time / non-Point-or-MultiPoint geometry is counted as invalid and dropped, but parsing continues. |
| `GoogleTimelineParser` | Handles both Google Timeline schemas in a single pass: legacy Takeout (`locations[].latitudeE7/longitudeE7/timestampMs`) and the new on-device export (`semanticSegments[].timelinePath[]` + `rawSignals[].position` with degree-suffix coord strings). Visit/activity inferences are intentionally skipped. |
| `GpxParser` | `XmlPullParser`-based. Collects `<wpt>` + `<rtept>` + `<trkpt>` uniformly into the flat locations table. Recognises Garmin's nested `TrackPointExtension` wrapper so sport-watch metadata (speed, course) lands on the row. |
| `KmlParser` | `XmlPullParser`-based. Reads `Placemark/Point/coordinates` (KML's `lon,lat[,alt]` order, flipped back internally) with `TimeStamp/when`. `LineString`-only Placemarks are dropped + counted as invalid since the KML schema doesn't carry per-vertex timestamps. |
diff --git a/apps/docs/docs/guides/data-import.md b/apps/docs/docs/guides/data-import.md
index 1b4bdb2b..917f3c15 100644
--- a/apps/docs/docs/guides/data-import.md
+++ b/apps/docs/docs/guides/data-import.md
@@ -18,7 +18,7 @@ The format is detected automatically from the file content; you don't pick it.
| Format | Extension | Source |
| --- | --- | --- |
-| **GeoJSON** | `.geojson` | Colota's own export. Any FeatureCollection of Point features with a `time` property also works. |
+| **GeoJSON** | `.geojson` | Colota's own export. Any FeatureCollection of Point or MultiPoint features with a `time` property also works. |
| **Google Timeline (legacy)** | `Records.json` | Older bulk Location History export from [Google Takeout](https://takeout.google.com). Google removed Location History from Takeout in late 2024 - use this format for files exported before then. |
| **Google Timeline (new)** | `.json` | On-device export from **Android Settings → Location → Location services → Timeline → Export Timeline data**. |
| **GPX** | `.gpx` | GPS Exchange Format. Sport watches (Garmin TrackPointExtension supported), Strava, generic trackers. |
@@ -64,7 +64,7 @@ Rows are dropped silently as "invalid" when any of the following hold:
- Missing latitude, longitude, or timestamp
- Coordinates out of range (latitude not in [-90, 90] or longitude not in [-180, 180])
- Timestamp more than 5 minutes in the future
-- Geometry type isn't a single Point (LineString-only KML Placemarks for example)
+- Geometry type isn't a Point or MultiPoint (LineString-only KML Placemarks for example)
The preview shows the invalid count so you can decide whether to proceed.
diff --git a/apps/mobile/android/app/src/main/java/com/colota/data/DatabaseHelper.kt b/apps/mobile/android/app/src/main/java/com/colota/data/DatabaseHelper.kt
index 4fd37369..c25f40ac 100644
--- a/apps/mobile/android/app/src/main/java/com/colota/data/DatabaseHelper.kt
+++ b/apps/mobile/android/app/src/main/java/com/colota/data/DatabaseHelper.kt
@@ -402,8 +402,8 @@ class DatabaseHelper private constructor(context: Context) :
val db = writableDatabase
val locationSql = """
INSERT INTO $TABLE_LOCATIONS
- (latitude, longitude, accuracy, altitude, speed, bearing, battery, timestamp, sent, created_at)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
+ (latitude, longitude, accuracy, altitude, speed, bearing, battery, battery_status, note, timestamp, sent, created_at)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""".trimIndent()
val queueSql = """
INSERT INTO $TABLE_QUEUE
@@ -427,9 +427,11 @@ class DatabaseHelper private constructor(context: Context) :
if (row.speed != null) locationStmt.bindLong(5, row.speed.toLong()) else locationStmt.bindNull(5)
if (row.bearing != null) locationStmt.bindDouble(6, row.bearing) else locationStmt.bindNull(6)
if (row.battery != null) locationStmt.bindLong(7, row.battery.toLong()) else locationStmt.bindNull(7)
- locationStmt.bindLong(8, row.timestamp)
- locationStmt.bindLong(9, sentFlag)
- locationStmt.bindLong(10, nowSec)
+ if (row.batteryStatus != null) locationStmt.bindLong(8, row.batteryStatus.toLong()) else locationStmt.bindNull(8)
+ if (row.note != null) locationStmt.bindString(9, row.note) else locationStmt.bindNull(9)
+ locationStmt.bindLong(10, row.timestamp)
+ locationStmt.bindLong(11, sentFlag)
+ locationStmt.bindLong(12, nowSec)
val locationId = locationStmt.executeInsert()
if (locationId == -1L) continue
inserted++
diff --git a/apps/mobile/android/app/src/main/java/com/colota/export/ExportConverters.kt b/apps/mobile/android/app/src/main/java/com/colota/export/ExportConverters.kt
index 396359a6..27c6fa89 100644
--- a/apps/mobile/android/app/src/main/java/com/colota/export/ExportConverters.kt
+++ b/apps/mobile/android/app/src/main/java/com/colota/export/ExportConverters.kt
@@ -47,6 +47,49 @@ class KmlCoordsCollector(cacheDir: File) : AutoCloseable {
}
}
+/** Spools the property columns to temp files (they trail the coords in the JSON) so large exports stay O(1) memory, like [KmlCoordsCollector]. */
+class GeoJsonColumnSpooler(cacheDir: File, private val columns: List<String>) : AutoCloseable {
+ // Per-instance name so two exports in the same dir don't share temp files.
+ private val files = columns.associateWith { File(cacheDir, "geojson_col_${System.identityHashCode(this)}_$it.txt") }
+ private val writers = files.mapValues { BufferedWriter(FileWriter(it.value)) }
+ var count = 0
+ private set
+
+ /** `tokens`: pre-formatted JSON values, one per column in [columns] order. */
+ fun addRow(tokens: List<String>) {
+ columns.forEachIndexed { i, name ->
+ val w = writers.getValue(name)
+ w.write(tokens[i])
+ w.newLine()
+ }
+ count++
+ }
+
+ fun writeProperties(w: Writer) {
+ writers.values.forEach { it.close() }
+ columns.forEachIndexed { idx, name ->
+ // Stream each token straight to the output (like KmlCoordsCollector.writeTo) rather than
+ // building the whole column string first, so peak memory is one token, not one column.
+ w.write(" \"$name\": [")
+ var first = true
+ BufferedReader(FileReader(files.getValue(name))).use { reader ->
+ reader.forEachLine { line ->
+ if (!first) w.write(", ")
+ w.write(line)
+ first = false
+ }
+ }
+ w.write("]")
+ w.write(if (idx < columns.size - 1) ",\n" else "\n")
+ }
+ }
+
+ override fun close() {
+ writers.values.forEach { try { it.close() } catch (_: Exception) {} }
+ files.values.forEach { it.delete() }
+ }
+}
+
object ExportConverters {
const val PAGE_SIZE = 10_000
@@ -145,12 +188,13 @@ object ExportConverters {
private sealed class FormatWriter(val extension: String, val mimeType: String) {
abstract fun writeHeader(w: Writer)
- abstract fun writeRow(w: Writer, row: ExportRow, globalIndex: Int, kml: KmlCoordsCollector?)
- abstract fun writeFooter(w: Writer, kml: KmlCoordsCollector?)
- open val usesKmlCoords: Boolean = false
+ abstract fun writeRow(w: Writer, row: ExportRow, globalIndex: Int, sink: AutoCloseable?)
+ abstract fun writeFooter(w: Writer, sink: AutoCloseable?)
+ /** Disk side channel for formats that spool (KML coords, GeoJSON columns); null otherwise. */
+ open fun newSideChannel(cacheDir: File): AutoCloseable? = null
- fun writeRows(w: Writer, rows: List<ExportRow>, globalOffset: Int, kml: KmlCoordsCollector?) {
- rows.forEachIndexed { i, row -> writeRow(w, row, globalOffset + i, kml) }
+ fun writeRows(w: Writer, rows: List<ExportRow>, globalOffset: Int, sink: AutoCloseable?) {
+ rows.forEachIndexed { i, row -> writeRow(w, row, globalOffset + i, sink) }
}
}
@@ -158,7 +202,7 @@ object ExportConverters {
override fun writeHeader(w: Writer) {
w.write("id,timestamp,iso_time,latitude,longitude,accuracy,altitude,speed,bearing,battery,battery_status,note\n")
}
- override fun writeRow(w: Writer, row: ExportRow, globalIndex: Int, kml: KmlCoordsCollector?) {
+ override fun writeRow(w: Writer, row: ExportRow, globalIndex: Int, sink: AutoCloseable?) {
w.write(listOf(
globalIndex, row.ts, isoTime(row.ts), jsNum(row.lat), jsNum(row.lon),
numOrZero(row.accuracy), numOrZero(row.altitude), numOrZero(row.speed), numOrZero(row.bearing), numOrZero(row.battery),
@@ -166,36 +210,48 @@ object ExportConverters {
).joinToString(","))
w.write("\n")
}
- override fun writeFooter(w: Writer, kml: KmlCoordsCollector?) {}
+ override fun writeFooter(w: Writer, sink: AutoCloseable?) {}
}
+ // The whole export is one MultiPoint feature: coords stream inline while the property columns
+ // (parallel arrays, index-aligned to coords) spool to disk and splice in at the footer, keeping memory O(1).
private object GeoJsonFormat : FormatWriter(".geojson", "application/json") {
+ private val COLUMNS = listOf("accuracy", "altitude", "speed", "bearing", "battery", "battery_status", "note", "time")
+
+ override fun newSideChannel(cacheDir: File): AutoCloseable = GeoJsonColumnSpooler(cacheDir, COLUMNS)
+
override fun writeHeader(w: Writer) {
- w.write("{\n \"type\": \"FeatureCollection\",\n \"features\": [\n")
+ w.write("{\n \"type\": \"FeatureCollection\",\n \"features\": [")
}
- override fun writeRow(w: Writer, row: ExportRow, globalIndex: Int, kml: KmlCoordsCollector?) {
- if (globalIndex > 0) w.write(",\n")
- w.write(""" {
- "type": "Feature",
- "geometry": {
- "type": "Point",
- "coordinates": [${jsNum(row.lon)}, ${jsNum(row.lat)}]
- },
- "properties": {
- "id": $globalIndex,
- "accuracy": ${jsonValue(row.accuracy)},
- "altitude": ${jsonValue(row.altitude)},
- "speed": ${jsonValue(row.speed)},
- "bearing": ${jsonValue(row.bearing)},
- "battery": ${jsonValue(row.battery)},
- "battery_status": ${jsonValue(batteryStatusLabel(row.batteryStatus))},
- "note": ${jsonValue(row.note)},
- "time": "${isoTime(row.ts)}"
- }
- }""")
+ override fun writeRow(w: Writer, row: ExportRow, globalIndex: Int, sink: AutoCloseable?) {
+ val coord = "[${jsNum(row.lon)}, ${jsNum(row.lat)}]"
+ if (globalIndex == 0) {
+ w.write("\n {\n \"type\": \"Feature\",\n \"geometry\": {\n \"type\": \"MultiPoint\",\n \"coordinates\": [\n $coord")
+ } else {
+ w.write(",\n $coord")
+ }
+ // Order must match COLUMNS.
+ (sink as? GeoJsonColumnSpooler)?.addRow(listOf(
+ jsonValue(row.accuracy),
+ jsonValue(row.altitude),
+ jsonValue(row.speed),
+ jsonValue(row.bearing),
+ jsonValue(row.battery),
+ jsonValue(batteryStatusLabel(row.batteryStatus)),
+ jsonValue(row.note),
+ "\"${isoTime(row.ts)}\"",
+ ))
}
- override fun writeFooter(w: Writer, kml: KmlCoordsCollector?) {
- w.write("\n ]\n}\n")
+ override fun writeFooter(w: Writer, sink: AutoCloseable?) {
+ val spool = sink as? GeoJsonColumnSpooler
+ if (spool == null || spool.count == 0) {
+ // No points: keep it a valid, empty FeatureCollection rather than an empty MultiPoint.
+ w.write("]\n}\n")
+ return
+ }
+ w.write("\n ]\n },\n \"properties\": {\n")
+ spool.writeProperties(w)
+ w.write(" }\n }\n ]\n}\n")
}
}
@@ -212,7 +268,7 @@ object ExportConverters {
<trkseg>
""")
}
- override fun writeRow(w: Writer, row: ExportRow, globalIndex: Int, kml: KmlCoordsCollector?) {
+ override fun writeRow(w: Writer, row: ExportRow, globalIndex: Int, sink: AutoCloseable?) {
val lat = String.format(Locale.US, "%.6f", row.lat)
val lon = String.format(Locale.US, "%.6f", row.lon)
w.write(""" <trkpt lat="$lat" lon="$lon">
@@ -229,7 +285,7 @@ object ExportConverters {
</trkpt>
""")
}
- override fun writeFooter(w: Writer, kml: KmlCoordsCollector?) {
+ override fun writeFooter(w: Writer, sink: AutoCloseable?) {
w.write(""" </trkseg>
</trk>
</gpx>
@@ -238,7 +294,7 @@ object ExportConverters {
}
private object KmlFormat : FormatWriter(".kml", "application/vnd.google-earth.kml+xml") {
- override val usesKmlCoords: Boolean = true
+ override fun newSideChannel(cacheDir: File): AutoCloseable = KmlCoordsCollector(cacheDir)
override fun writeHeader(w: Writer) {
w.write("""<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
@@ -253,8 +309,8 @@ object ExportConverters {
</Style>
""")
}
- override fun writeRow(w: Writer, row: ExportRow, globalIndex: Int, kml: KmlCoordsCollector?) {
- kml?.add("${jsNum(row.lon)},${jsNum(row.lat)},${numOrZero(row.altitude)}")
+ override fun writeRow(w: Writer, row: ExportRow, globalIndex: Int, sink: AutoCloseable?) {
+ (sink as? KmlCoordsCollector)?.add("${jsNum(row.lon)},${jsNum(row.lat)},${numOrZero(row.altitude)}")
w.write(""" <Placemark>
<TimeStamp><when>${isoTime(row.ts)}</when></TimeStamp>
<description>Accuracy: ${numOrZero(row.accuracy)}m, Speed: ${numOrZero(row.speed)}m/s</description>
@@ -273,7 +329,7 @@ object ExportConverters {
</Placemark>
""")
}
- override fun writeFooter(w: Writer, kml: KmlCoordsCollector?) {
+ override fun writeFooter(w: Writer, sink: AutoCloseable?) {
w.write(""" <Placemark>
<name>Track Path</name>
<styleUrl>#pathStyle</styleUrl>
@@ -281,7 +337,7 @@ object ExportConverters {
<tessellate>1</tessellate>
<coordinates>
""")
- kml?.writeTo(w)
+ (sink as? KmlCoordsCollector)?.writeTo(w)
w.write("""
</coordinates>
</LineString>
@@ -313,12 +369,12 @@ object ExportConverters {
fetchPage: (limit: Int, offset: Int) -> List<Map<String, Any?>>
): Int {
val writer = forFormat(format)
- val coordsCollector = if (writer.usesKmlCoords) KmlCoordsCollector(outputFile.parentFile!!) else null
+ val sink = writer.newSideChannel(outputFile.parentFile!!)
var totalRows = 0
var offset = 0
var cancelled = false
- coordsCollector.use {
+ sink.use {
OutputStreamWriter(outputFile.outputStream(), Charsets.UTF_8).use { w ->
writer.writeHeader(w)
@@ -326,12 +382,12 @@ object ExportConverters {
if (shouldCancel()) { cancelled = true; break }
val page = fetchPage(pageSize, offset)
if (page.isEmpty()) break
- writer.writeRows(w, page.map(ExportRow::from), offset, coordsCollector)
+ writer.writeRows(w, page.map(ExportRow::from), offset, sink)
totalRows += page.size
offset += pageSize
}
- if (!cancelled) writer.writeFooter(w, coordsCollector)
+ if (!cancelled) writer.writeFooter(w, sink)
}
}
return totalRows
@@ -346,32 +402,34 @@ object ExportConverters {
forFormat(format).writeHeader(writer)
}
- /** `coordsCollector` is required for KML (spills LineString coords to disk). */
+ /** Opens the disk side channel for [format]; null for formats that don't spool. */
+ fun newSideChannel(format: String, cacheDir: File): AutoCloseable? =
+ forFormat(format).newSideChannel(cacheDir)
+
+ /** `sink` comes from [newSideChannel]; null for formats that don't spool. */
fun writeRows(
writer: Writer,
format: String,
rows: List<Map<String, Any?>>,
globalOffset: Int,
- coordsCollector: KmlCoordsCollector?
+ sink: AutoCloseable?
) {
- forFormat(format).writeRows(writer, rows.map(ExportRow::from), globalOffset, coordsCollector)
+ forFormat(format).writeRows(writer, rows.map(ExportRow::from), globalOffset, sink)
}
- fun writeFooter(writer: Writer, format: String, coordsCollector: KmlCoordsCollector?) {
- forFormat(format).writeFooter(writer, coordsCollector)
+ fun writeFooter(writer: Writer, format: String, sink: AutoCloseable?) {
+ forFormat(format).writeFooter(writer, sink)
}
fun convert(format: String, rows: List<Map<String, Any?>>): String {
val writer = forFormat(format)
val sw = java.io.StringWriter()
- val coordsCollector = if (writer.usesKmlCoords) {
- KmlCoordsCollector(java.io.File(System.getProperty("java.io.tmpdir")!!))
- } else null
+ val sink = writer.newSideChannel(java.io.File(System.getProperty("java.io.tmpdir")!!))
- coordsCollector.use {
+ sink.use {
writer.writeHeader(sw)
- writer.writeRows(sw, rows.map(ExportRow::from), 0, coordsCollector)
- writer.writeFooter(sw, coordsCollector)
+ writer.writeRows(sw, rows.map(ExportRow::from), 0, sink)
+ writer.writeFooter(sw, sink)
}
return sw.toString()
}
@@ -452,36 +510,37 @@ object ExportConverters {
return sb.toString()
}
+ // One MultiPoint feature per trip. In-memory (not spooled like the flat export) is fine - trips are day-sized.
private fun tripsToGeoJson(trips: List<TripExport>): String {
val features = ArrayList<String>()
for (trip in trips) {
- trip.rows.forEachIndexed { i, row ->
- val ts = rowTs(row)
- features.add(
- " {\n" +
- " \"type\": \"Feature\",\n" +
- " \"geometry\": {\n" +
- " \"type\": \"Point\",\n" +
- " \"coordinates\": [\n" +
- " ${numOrZero(row["longitude"])},\n" +
- " ${numOrZero(row["latitude"])}\n" +
- " ]\n" +
- " },\n" +
- " \"properties\": {\n" +
- " \"trip\": ${trip.index},\n" +
- " \"id\": $i,\n" +
- " \"accuracy\": ${jsonNum(row["accuracy"])},\n" +
- " \"altitude\": ${jsonNum(row["altitude"])},\n" +
- " \"speed\": ${jsonNum(row["speed"])},\n" +
- " \"bearing\": ${jsonNum(row["bearing"])},\n" +
- " \"battery\": ${jsonNum(row["battery"])},\n" +
- " \"battery_status\": ${jsonValue(batteryStatusLabel(row["battery_status"]))},\n" +
- " \"note\": ${jsonValue(row["note"])},\n" +
- " \"time\": \"${isoTime(ts)}\"\n" +
- " }\n" +
- " }"
- )
+ if (trip.rows.isEmpty()) continue
+ val coords = trip.rows.joinToString(",\n ") {
+ "[${numOrZero(it["longitude"])}, ${numOrZero(it["latitude"])}]"
}
+ fun col(transform: (Map<String, Any?>) -> String) = trip.rows.joinToString(", ", transform = transform)
+ features.add(
+ " {\n" +
+ " \"type\": \"Feature\",\n" +
+ " \"geometry\": {\n" +
+ " \"type\": \"MultiPoint\",\n" +
+ " \"coordinates\": [\n" +
+ " $coords\n" +
+ " ]\n" +
+ " },\n" +
+ " \"properties\": {\n" +
+ " \"trip\": ${trip.index},\n" +
+ " \"accuracy\": [${col { jsonNum(it["accuracy"]) }}],\n" +
+ " \"altitude\": [${col { jsonNum(it["altitude"]) }}],\n" +
+ " \"speed\": [${col { jsonNum(it["speed"]) }}],\n" +
+ " \"bearing\": [${col { jsonNum(it["bearing"]) }}],\n" +
+ " \"battery\": [${col { jsonNum(it["battery"]) }}],\n" +
+ " \"battery_status\": [${col { jsonValue(batteryStatusLabel(it["battery_status"])) }}],\n" +
+ " \"note\": [${col { jsonValue(it["note"]) }}],\n" +
+ " \"time\": [${col { "\"${isoTime(rowTs(it))}\"" }}]\n" +
+ " }\n" +
+ " }"
+ )
}
val featuresBlock = if (features.isEmpty()) "[]" else "[\n${features.joinToString(",\n")}\n ]"
return "{\n \"type\": \"FeatureCollection\",\n \"features\": $featuresBlock\n}"
diff --git a/apps/mobile/android/app/src/main/java/com/colota/importer/GeoJsonParser.kt b/apps/mobile/android/app/src/main/java/com/colota/importer/GeoJsonParser.kt
index 53e603d1..0c1290dd 100644
--- a/apps/mobile/android/app/src/main/java/com/colota/importer/GeoJsonParser.kt
+++ b/apps/mobile/android/app/src/main/java/com/colota/importer/GeoJsonParser.kt
@@ -10,8 +10,8 @@ import android.util.JsonToken
import java.io.InputStream
import java.util.concurrent.atomic.AtomicBoolean
-/** Streaming GeoJSON parser. Reads FeatureCollection of Point features; non-Point
- * features are counted invalid and skipped. */
+/** Streaming GeoJSON parser. Reads Point (scalar props) or MultiPoint (columnar, parallel-array
+ * props) features from a FeatureCollection; other geometries are counted invalid and skipped. */
object GeoJsonParser {
fun parse(
@@ -31,8 +31,9 @@ object GeoJsonParser {
reader.beginArray()
while (reader.hasNext()) {
if (cancelled.get()) throw InterruptedException("Import cancelled")
- val row = readFeature(reader, nowSec)
- if (row != null) rows.add(row) else invalid++
+ val result = readFeature(reader, nowSec)
+ rows.addAll(result.rows)
+ invalid += result.invalid
}
reader.endArray()
}
@@ -45,16 +46,21 @@ object GeoJsonParser {
return ParseResult(rows = rows, invalid = invalid)
}
- private fun readFeature(reader: JsonReader, nowSec: Long): ImportRow? {
- var lat: Double? = null
- var lon: Double? = null
- var ts: Long? = null
- var accuracy: Int? = null
- var altitude: Int? = null
- var speed: Int? = null
- var bearing: Double? = null
- var battery: Int? = null
+ private class FeatureResult(val rows: List<ImportRow>, val invalid: Int)
+
+ private fun readFeature(reader: JsonReader, nowSec: Long): FeatureResult {
var geometryType: String? = null
+ var rawCoords: Coords? = null
+ // Read as columns: a scalar becomes a single-element list so Point and MultiPoint share one
+ // zip-by-index path below. Null = property absent.
+ var times: List<Long?>? = null
+ var accuracy: List<Int?>? = null
+ var altitude: List<Int?>? = null
+ var speed: List<Int?>? = null
+ var bearing: List<Double?>? = null
+ var battery: List<Int?>? = null
+ var batteryStatus: List<Int?>? = null
+ var note: List<String?>? = null
reader.beginObject()
while (reader.hasNext()) {
@@ -72,11 +78,7 @@ object GeoJsonParser {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull()
} else {
- val coords = readCoordinates(reader)
- if (coords != null) {
- lon = coords.first
- lat = coords.second
- }
+ rawCoords = readCoords(reader)
}
}
else -> reader.skipValue()
@@ -92,12 +94,14 @@ object GeoJsonParser {
reader.beginObject()
while (reader.hasNext()) {
when (reader.nextName()) {
- "time", "timestamp" -> ts = readTimestamp(reader)
- "accuracy" -> accuracy = reader.readNullableInt()
- "altitude", "elevation", "ele" -> altitude = reader.readNullableInt()
- "speed", "velocity" -> speed = reader.readNullableInt()
- "bearing", "heading" -> bearing = reader.readNullableDouble()
- "battery" -> battery = reader.readNullableInt()
+ "time", "timestamp" -> times = readList(reader) { readTimestamp(it) }
+ "accuracy" -> accuracy = readList(reader) { it.readNullableInt() }
+ "altitude", "elevation", "ele" -> altitude = readList(reader) { it.readNullableInt() }
+ "speed", "velocity" -> speed = readList(reader) { it.readNullableInt() }
+ "bearing", "heading" -> bearing = readList(reader) { it.readNullableDouble() }
+ "battery" -> battery = readList(reader) { it.readNullableInt() }
+ "battery_status" -> batteryStatus = readList(reader) { readBatteryStatus(it) }
+ "note" -> note = readList(reader) { readNullableString(it) }
else -> reader.skipValue()
}
}
@@ -108,42 +112,117 @@ object GeoJsonParser {
}
reader.endObject()
- if (geometryType != "Point") return null
- val tsVal = ts ?: return null
- val latVal = lat ?: return null
- val lonVal = lon ?: return null
- if (!isValidLocation(latVal, lonVal, tsVal, nowSec)) return null
-
- return ImportRow(
- timestamp = tsVal,
- latitude = latVal,
- longitude = lonVal,
- accuracy = accuracy,
- altitude = altitude,
- speed = speed,
- bearing = bearing,
- battery = battery,
- )
+ // Coordinates and type may appear in any key order, so resolve the point list only now.
+ val points: List<Pair<Double, Double>>? = when (geometryType) {
+ "Point" -> (rawCoords as? Coords.Single)?.let { listOf(it.lon to it.lat) }
+ "MultiPoint" -> (rawCoords as? Coords.Multi)?.points
+ else -> null
+ }
+ // Wrong geometry, or coords malformed for the declared type: one invalid feature.
+ if (points == null) return FeatureResult(emptyList(), 1)
+
+ val out = ArrayList<ImportRow>(points.size)
+ var invalid = 0
+ for (i in points.indices) {
+ val (lon, lat) = points[i]
+ val ts = times?.getOrNull(i)
+ if (ts == null || !isValidLocation(lat, lon, ts, nowSec)) {
+ invalid++
+ continue
+ }
+ out.add(
+ ImportRow(
+ timestamp = ts,
+ latitude = lat,
+ longitude = lon,
+ accuracy = accuracy?.getOrNull(i),
+ altitude = altitude?.getOrNull(i),
+ speed = speed?.getOrNull(i),
+ bearing = bearing?.getOrNull(i),
+ battery = battery?.getOrNull(i),
+ note = note?.getOrNull(i),
+ batteryStatus = batteryStatus?.getOrNull(i),
+ )
+ )
+ }
+ return FeatureResult(out, invalid)
+ }
+
+ private sealed class Coords {
+ object Invalid : Coords()
+ data class Single(val lon: Double, val lat: Double) : Coords()
+ data class Multi(val points: List<Pair<Double, Double>>) : Coords()
}
- // Returns null on non-Point shapes; still consumes the array to keep the reader aligned.
- private fun readCoordinates(reader: JsonReader): Pair<Double, Double>? {
+ // Flat [lon,lat] -> Single, nested [[lon,lat],...] -> Multi. Type decides Point vs MultiPoint,
+ // since MultiPoint and LineString have the same coordinate nesting.
+ private fun readCoords(reader: JsonReader): Coords {
reader.beginArray()
- if (!reader.hasNext() || reader.peek() != JsonToken.NUMBER) {
- while (reader.hasNext()) reader.skipValue()
+ if (!reader.hasNext()) {
reader.endArray()
+ return Coords.Multi(emptyList())
+ }
+ return when (reader.peek()) {
+ JsonToken.NUMBER -> {
+ val lon = reader.nextDouble()
+ if (!reader.hasNext() || reader.peek() != JsonToken.NUMBER) {
+ drainArray(reader)
+ return Coords.Invalid
+ }
+ val lat = reader.nextDouble()
+ drainArray(reader)
+ Coords.Single(lon, lat)
+ }
+ JsonToken.BEGIN_ARRAY -> {
+ val points = ArrayList<Pair<Double, Double>>()
+ while (reader.hasNext()) {
+ val pair = readInnerPair(reader)
+ if (pair != null) points.add(pair)
+ }
+ reader.endArray()
+ Coords.Multi(points)
+ }
+ else -> {
+ drainArray(reader)
+ Coords.Invalid
+ }
+ }
+ }
+
+ // One [lon,lat,...] sub-array; null if it's not a coord pair (e.g. deeper nesting).
+ private fun readInnerPair(reader: JsonReader): Pair<Double, Double>? {
+ if (reader.peek() != JsonToken.BEGIN_ARRAY) {
+ reader.skipValue()
return null
}
- val first = reader.nextDouble()
+ reader.beginArray()
if (!reader.hasNext() || reader.peek() != JsonToken.NUMBER) {
- while (reader.hasNext()) reader.skipValue()
- reader.endArray()
+ drainArray(reader)
return null
}
- val second = reader.nextDouble()
+ val lon = reader.nextDouble()
+ if (!reader.hasNext() || reader.peek() != JsonToken.NUMBER) {
+ drainArray(reader)
+ return null
+ }
+ val lat = reader.nextDouble()
+ drainArray(reader)
+ return lon to lat
+ }
+
+ private fun drainArray(reader: JsonReader) {
while (reader.hasNext()) reader.skipValue()
reader.endArray()
- return first to second
+ }
+
+ // Array -> one entry per element; scalar -> single-element list. Short arrays null-fill via getOrNull.
+ private inline fun <T> readList(reader: JsonReader, readOne: (JsonReader) -> T?): List<T?> {
+ if (reader.peek() != JsonToken.BEGIN_ARRAY) return listOf(readOne(reader))
+ val out = ArrayList<T?>()
+ reader.beginArray()
+ while (reader.hasNext()) out.add(readOne(reader))
+ reader.endArray()
+ return out
}
private fun readTimestamp(reader: JsonReader): Long? {
@@ -161,6 +240,27 @@ object GeoJsonParser {
}
}
+ private fun readNullableString(reader: JsonReader): String? = when (reader.peek()) {
+ JsonToken.NULL -> { reader.nextNull(); null }
+ JsonToken.STRING -> reader.nextString()
+ else -> { reader.skipValue(); null }
+ }
+
+ // Accepts Colota's exported labels and Overland-style strings, or a raw numeric code.
+ private fun readBatteryStatus(reader: JsonReader): Int? = when (reader.peek()) {
+ JsonToken.NULL -> { reader.nextNull(); null }
+ JsonToken.NUMBER -> reader.nextDouble().toInt()
+ JsonToken.STRING -> batteryStatusCode(reader.nextString())
+ else -> { reader.skipValue(); null }
+ }
+
+ private fun batteryStatusCode(label: String): Int? = when (label.lowercase()) {
+ "charging" -> 2
+ "full" -> 3
+ "unplugged/discharging", "unplugged", "discharging" -> 1
+ "unknown" -> 0
+ else -> null
+ }
}
internal fun isValidLocation(lat: Double, lon: Double, tsSec: Long, nowSec: Long): Boolean {
diff --git a/apps/mobile/android/app/src/main/java/com/colota/importer/ImportRow.kt b/apps/mobile/android/app/src/main/java/com/colota/importer/ImportRow.kt
index 0ff49001..267823f0 100644
--- a/apps/mobile/android/app/src/main/java/com/colota/importer/ImportRow.kt
+++ b/apps/mobile/android/app/src/main/java/com/colota/importer/ImportRow.kt
@@ -15,4 +15,6 @@ data class ImportRow(
val speed: Int?,
val bearing: Double?,
val battery: Int?,
+ val note: String? = null,
+ val batteryStatus: Int? = null,
)
diff --git a/apps/mobile/android/app/src/main/java/com/colota/importer/LocationImporter.kt b/apps/mobile/android/app/src/main/java/com/colota/importer/LocationImporter.kt
index ef5171ca..5efae612 100644
--- a/apps/mobile/android/app/src/main/java/com/colota/importer/LocationImporter.kt
+++ b/apps/mobile/android/app/src/main/java/com/colota/importer/LocationImporter.kt
@@ -144,7 +144,7 @@ object LocationImporter {
location = location,
timestamp = row.timestamp,
batteryLevel = row.battery ?: 0,
- batteryStatus = 0,
+ batteryStatus = row.batteryStatus ?: 0,
fieldMap = options.fieldMap,
customFields = options.customFields,
apiFormat = options.apiFormat,
diff --git a/apps/mobile/android/app/src/test/java/com/Colota/export/ExportConvertersTest.kt b/apps/mobile/android/app/src/test/java/com/Colota/export/ExportConvertersTest.kt
index d417cd46..5ed0c201 100644
--- a/apps/mobile/android/app/src/test/java/com/Colota/export/ExportConvertersTest.kt
+++ b/apps/mobile/android/app/src/test/java/com/Colota/export/ExportConvertersTest.kt
@@ -91,25 +91,37 @@ class ExportConvertersTest {
// --- GeoJSON ---
@Test
- fun `convert GeoJSON produces valid structure`() {
+ fun `convert GeoJSON produces a single columnar MultiPoint feature`() {
val json = ExportConverters.convert("geojson", sampleRows)
assertTrue(json.contains("\"type\": \"FeatureCollection\""))
assertTrue(json.contains("\"type\": \"Feature\""))
- assertTrue(json.contains("\"type\": \"Point\""))
+ assertTrue(json.contains("\"type\": \"MultiPoint\""))
+ // Exactly one Feature for the whole export (columnar), not one per point.
+ assertEquals(1, Regex("\"type\": \"Feature\"").findAll(json).count())
+ assertFalse(json.contains("\"type\": \"Point\""))
}
@Test
fun `convert GeoJSON contains coordinates in lon-lat order`() {
val json = ExportConverters.convert("geojson", sampleRows)
assertTrue(json.contains("[13.405, 52.52]"))
+ assertTrue(json.contains("[2.3522, 48.8566]"))
}
@Test
- fun `convert GeoJSON contains properties`() {
+ fun `convert GeoJSON emits properties as parallel arrays aligned to coordinates`() {
val json = ExportConverters.convert("geojson", sampleRows)
- assertTrue(json.contains("\"accuracy\": 10"))
- assertTrue(json.contains("\"speed\": 1.2"))
- assertTrue(json.contains("\"battery\": 85"))
+ assertTrue(json.contains("\"accuracy\": [10, 15]"))
+ assertTrue(json.contains("\"speed\": [1.2, 0.5]"))
+ assertTrue(json.contains("\"battery\": [85, 72]"))
+ assertTrue(json.contains("\"time\": [\""))
+ }
+
+ @Test
+ fun `convert GeoJSON keeps a single point as a MultiPoint`() {
+ val json = ExportConverters.convert("geojson", listOf(sampleRows[0]))
+ assertTrue(json.contains("\"type\": \"MultiPoint\""))
+ assertTrue(json.contains("\"accuracy\": [10]")) // length-1 array, not a scalar
}
// --- GPX ---
@@ -181,7 +193,7 @@ class ExportConvertersTest {
fun `GeoJSON JSON-escapes the note and emits null when absent`() {
val json = ExportConverters.convert("geojson", noteRows)
assertTrue(json.contains("\\\"big\\\""))
- assertTrue(json.contains("\"note\": null")) // the second point has no note
+ assertTrue(json.contains(", null]")) // the note column ends with null for the second point
}
@Test
@@ -270,19 +282,19 @@ class ExportConvertersTest {
private fun streamToString(format: String, rows: List<Map<String, Any?>>, chunks: List<List<Map<String, Any?>>>? = null): String {
val writer = StringWriter()
- val coordsCollector = if (format == "kml") KmlCoordsCollector(tempFolder.root) else null
- coordsCollector.use {
+ val sink = ExportConverters.newSideChannel(format, tempFolder.root)
+ sink.use {
ExportConverters.writeHeader(writer, format)
if (chunks != null) {
var offset = 0
for (chunk in chunks) {
- ExportConverters.writeRows(writer, format, chunk, offset, coordsCollector)
+ ExportConverters.writeRows(writer, format, chunk, offset, sink)
offset += chunk.size
}
} else {
- ExportConverters.writeRows(writer, format, rows, 0, coordsCollector)
+ ExportConverters.writeRows(writer, format, rows, 0, sink)
}
- ExportConverters.writeFooter(writer, format, coordsCollector)
+ ExportConverters.writeFooter(writer, format, sink)
}
return writer.toString()
}
@@ -338,8 +350,10 @@ class ExportConvertersTest {
assertTrue(csvLines[2].startsWith("1,"))
val geojsonResult = streamToString("geojson", emptyList(), chunks = listOf(chunk1, chunk2))
- assertTrue(geojsonResult.contains("\"id\": 0"))
- assertTrue(geojsonResult.contains("\"id\": 1"))
+ // Both chunks fold into one MultiPoint feature.
+ assertTrue(geojsonResult.contains("[13.405, 52.52]"))
+ assertTrue(geojsonResult.contains("[2.3522, 48.8566]"))
+ assertEquals(1, Regex("\"type\": \"Feature\"").findAll(geojsonResult).count())
val gpxResult = streamToString("gpx", emptyList(), chunks = listOf(chunk1, chunk2))
assertTrue(gpxResult.contains("lat=\"52.520000\""))
@@ -363,6 +377,8 @@ class ExportConvertersTest {
val geojsonResult = streamToString("geojson", emptyList())
assertTrue(geojsonResult.contains("FeatureCollection"))
+ assertTrue("empty export is an empty FeatureCollection, not an empty MultiPoint", geojsonResult.contains("\"features\": []"))
+ assertFalse(geojsonResult.contains("MultiPoint"))
}
@Test
@@ -384,8 +400,8 @@ class ExportConvertersTest {
val csv = ExportConverters.convert("csv", sampleRows)
assertTrue(csv.lines()[1].endsWith(",Charging,")) // battery_status label, then empty note (last column)
val gj = ExportConverters.convert("geojson", sampleRows)
- assertTrue(gj.contains("\"bearing\": 180")) // whole double -> no trailing ".0"
- assertTrue(gj.contains("\"battery_status\": \"Charging\""))
+ assertTrue(gj.contains("\"bearing\": [180")) // whole double -> no trailing ".0"
+ assertTrue(gj.contains("\"battery_status\": [\"Charging\""))
val gpx = ExportConverters.convert("gpx", sampleRows)
assertTrue(gpx.contains("<bearing>180</bearing>"))
assertTrue(gpx.contains("<battery_status>Charging</battery_status>"))
@@ -450,7 +466,7 @@ class ExportConvertersTest {
assertTrue(csv.contains("\"deer, \"\"big\"\" <antlers>\""))
val gj = ExportConverters.convertTrips("geojson", trips)
assertTrue(gj.contains("\\\"big\\\""))
- assertTrue(gj.contains("\"note\": null")) // the second point has no note
+ assertTrue(gj.contains(", null]")) // the note column ends with null for the second point
val gpx = ExportConverters.convertTrips("gpx", trips)
assertTrue(gpx.contains("<note>deer, &quot;big&quot; &lt;antlers&gt;</note>"))
assertTrue(gpx.contains("<note></note>"))
diff --git a/apps/mobile/android/app/src/test/java/com/Colota/importer/GeoJsonParserTest.kt b/apps/mobile/android/app/src/test/java/com/Colota/importer/GeoJsonParserTest.kt
index e847fd20..d8b73590 100644
--- a/apps/mobile/android/app/src/test/java/com/Colota/importer/GeoJsonParserTest.kt
+++ b/apps/mobile/android/app/src/test/java/com/Colota/importer/GeoJsonParserTest.kt
@@ -5,6 +5,7 @@
package com.Colota.importer
+import com.Colota.export.ExportConverters
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
@@ -56,6 +57,186 @@ class GeoJsonParserTest {
assertEquals(1_704_110_400L, row.timestamp)
}
+ @Test
+ fun `imports note and battery_status from a Point feature`() {
+ val json = """
+ {
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "geometry": { "type": "Point", "coordinates": [13.4, 52.5] },
+ "properties": {
+ "time": "2024-01-01T12:00:00.000Z",
+ "battery_status": "Charging",
+ "note": "deer crossing"
+ }
+ }
+ ]
+ }
+ """.trimIndent()
+
+ val result = GeoJsonParser.parse(json.byteInputStream(), cancelled, nowSec)
+ assertEquals(0, result.invalid)
+ assertEquals(1, result.rows.size)
+ assertEquals("deer crossing", result.rows[0].note)
+ assertEquals(2, result.rows[0].batteryStatus) // "Charging" -> BatteryStatus.CHARGING
+ }
+
+ @Test
+ fun `parses a columnar MultiPoint feature into one row per point`() {
+ val json = """
+ {
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "geometry": {
+ "type": "MultiPoint",
+ "coordinates": [ [13.4, 52.5], [13.41, 52.51] ]
+ },
+ "properties": {
+ "accuracy": [5, 8],
+ "altitude": [30, 31],
+ "battery": [80, 79],
+ "battery_status": ["Charging", "Full"],
+ "note": ["start", null],
+ "time": ["2024-01-01T12:00:00.000Z", "2024-01-01T12:01:00.000Z"]
+ }
+ }
+ ]
+ }
+ """.trimIndent()
+
+ val result = GeoJsonParser.parse(json.byteInputStream(), cancelled, nowSec)
+ assertEquals(0, result.invalid)
+ assertEquals(2, result.rows.size)
+
+ val first = result.rows[0]
+ assertEquals(52.5, first.latitude, 1e-9)
+ assertEquals(13.4, first.longitude, 1e-9)
+ assertEquals(5, first.accuracy)
+ assertEquals(80, first.battery)
+ assertEquals(2, first.batteryStatus)
+ assertEquals("start", first.note)
+ assertEquals(1_704_110_400L, first.timestamp)
+
+ val second = result.rows[1]
+ assertEquals(52.51, second.latitude, 1e-9)
+ assertEquals(8, second.accuracy)
+ assertEquals(3, second.batteryStatus) // "Full"
+ assertNull(second.note) // null-filled
+ assertEquals(1_704_110_460L, second.timestamp)
+ }
+
+ @Test
+ fun `MultiPoint points without a paired time are counted invalid`() {
+ // Two coordinates but only one time -> the second point can't be placed in time.
+ val json = """
+ {
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "geometry": { "type": "MultiPoint", "coordinates": [ [13.4, 52.5], [13.41, 52.51] ] },
+ "properties": { "time": ["2024-01-01T12:00:00.000Z"] }
+ }
+ ]
+ }
+ """.trimIndent()
+
+ val result = GeoJsonParser.parse(json.byteInputStream(), cancelled, nowSec)
+ assertEquals(1, result.rows.size)
+ assertEquals(1, result.invalid)
+ }
+
+ @Test
+ fun `round-trips a multi-point export back into equal rows`() {
+ // The feature's headline promise: export -> import must preserve every field, including note
+ // and battery_status. Drives the real writer (ExportConverters) into the real parser.
+ val rows = listOf(
+ mapOf<String, Any?>(
+ "latitude" to 52.5, "longitude" to 13.4, "timestamp" to 1_700_000_000L,
+ "accuracy" to 5, "altitude" to 30, "speed" to 2, "bearing" to 180.0,
+ "battery" to 80, "battery_status" to 2L, "note" to "deer, \"big\" <antlers>",
+ ),
+ mapOf<String, Any?>(
+ "latitude" to 48.8566, "longitude" to 2.3522, "timestamp" to 1_700_003_600L,
+ "accuracy" to 8, "altitude" to 40, "speed" to 3, "bearing" to 90.0,
+ "battery" to 79, "battery_status" to 3L,
+ ),
+ )
+
+ val json = ExportConverters.convert("geojson", rows)
+ val result = GeoJsonParser.parse(json.byteInputStream(), cancelled, nowSec)
+
+ assertEquals(0, result.invalid)
+ assertEquals(2, result.rows.size)
+ val a = result.rows[0]
+ assertEquals(52.5, a.latitude, 1e-9)
+ assertEquals(13.4, a.longitude, 1e-9)
+ assertEquals(1_700_000_000L, a.timestamp)
+ assertEquals(5, a.accuracy)
+ assertEquals(30, a.altitude)
+ assertEquals(2, a.speed)
+ assertEquals(180.0, a.bearing!!, 1e-9)
+ assertEquals(80, a.battery)
+ assertEquals(2, a.batteryStatus) // "Charging" label survives the round-trip
+ assertEquals("deer, \"big\" <antlers>", a.note) // JSON escaping round-trips
+ val b = result.rows[1]
+ assertEquals(3, b.batteryStatus) // "Full"
+ assertNull(b.note) // absent note stays null
+ }
+
+ @Test
+ fun `round-trips a single-point export (still a MultiPoint) back into one row`() {
+ val rows = listOf(
+ mapOf<String, Any?>(
+ "latitude" to 40.0, "longitude" to -3.0, "timestamp" to 1_700_000_000L,
+ "accuracy" to 12, "battery" to 55, "battery_status" to 1L, "note" to "solo",
+ ),
+ )
+
+ val json = ExportConverters.convert("geojson", rows)
+ assertTrue("a single point must still export as a MultiPoint", json.contains("\"MultiPoint\""))
+
+ val result = GeoJsonParser.parse(json.byteInputStream(), cancelled, nowSec)
+ assertEquals(0, result.invalid)
+ assertEquals(1, result.rows.size)
+ val r = result.rows[0]
+ assertEquals(40.0, r.latitude, 1e-9)
+ assertEquals(-3.0, r.longitude, 1e-9)
+ assertEquals(12, r.accuracy)
+ assertEquals(55, r.battery)
+ assertEquals(1, r.batteryStatus) // "Unplugged/Discharging"
+ assertEquals("solo", r.note)
+ }
+
+ @Test
+ fun `maps every battery_status label, Overland alias and numeric code back to its code`() {
+ // Colota labels (Unknown/Unplugged-Discharging/Charging/Full), an Overland-style alias, a raw
+ // numeric code, and an unrecognised label (-> null). Exercises readBatteryStatus's leniency.
+ val json = """
+ {
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "geometry": { "type": "MultiPoint", "coordinates": [ [1.0,1.0],[2.0,1.0],[3.0,1.0],[4.0,1.0],[5.0,1.0],[6.0,1.0],[7.0,1.0] ] },
+ "properties": {
+ "time": ["2024-01-01T12:00:00.000Z","2024-01-01T12:00:00.000Z","2024-01-01T12:00:00.000Z","2024-01-01T12:00:00.000Z","2024-01-01T12:00:00.000Z","2024-01-01T12:00:00.000Z","2024-01-01T12:00:00.000Z"],
+ "battery_status": ["Unknown","Unplugged/Discharging","Charging","Full","unplugged",1,"nonsense"]
+ }
+ }
+ ]
+ }
+ """.trimIndent()
+
+ val result = GeoJsonParser.parse(json.byteInputStream(), cancelled, nowSec)
+ assertEquals(0, result.invalid)
+ assertEquals(listOf(0, 1, 2, 3, 1, 1, null), result.rows.map { it.batteryStatus })
+ }
+
@Test
fun `rejects features without a recognised time`() {
val json = """
diff --git a/apps/mobile/android/app/src/test/resources/golden/export/trip.geojson b/apps/mobile/android/app/src/test/resources/golden/export/trip.geojson
index 67c97a83..2bf35765 100644
--- a/apps/mobile/android/app/src/test/resources/golden/export/trip.geojson
+++ b/apps/mobile/android/app/src/test/resources/golden/export/trip.geojson
@@ -4,89 +4,43 @@
{
"type": "Feature",
"geometry": {
- "type": "Point",
+ "type": "MultiPoint",
"coordinates": [
- 11.576124,
- 48.137154
+ [11.576124, 48.137154],
+ [11.577003, 48.138001]
]
},
"properties": {
"trip": 1,
- "id": 0,
- "accuracy": 8.5,
- "altitude": 520.2,
- "speed": 1.4,
- "bearing": 270.5,
- "battery": 91,
- "battery_status": "Charging",
- "note": null,
- "time": "2023-11-14T22:13:20.000Z"
+ "accuracy": [8.5, 12],
+ "altitude": [520.2, 525],
+ "speed": [1.4, 2],
+ "bearing": [270.5, 275],
+ "battery": [91, 90],
+ "battery_status": ["Charging", "Full"],
+ "note": [null, null],
+ "time": ["2023-11-14T22:13:20.000Z", "2023-11-14T22:14:20.000Z"]
}
},
{
"type": "Feature",
"geometry": {
- "type": "Point",
+ "type": "MultiPoint",
"coordinates": [
- 11.577003,
- 48.138001
- ]
- },
- "properties": {
- "trip": 1,
- "id": 1,
- "accuracy": 12,
- "altitude": 525,
- "speed": 2,
- "bearing": 275,
- "battery": 90,
- "battery_status": "Full",
- "note": null,
- "time": "2023-11-14T22:14:20.000Z"
- }
- },
- {
- "type": "Feature",
- "geometry": {
- "type": "Point",
- "coordinates": [
- 11.58,
- 48.14
- ]
- },
- "properties": {
- "trip": 2,
- "id": 0,
- "accuracy": 5,
- "altitude": 530,
- "speed": 3,
- "bearing": 10,
- "battery": 88,
- "battery_status": "Unplugged/Discharging",
- "note": null,
- "time": "2023-11-14T22:30:00.000Z"
- }
- },
- {
- "type": "Feature",
- "geometry": {
- "type": "Point",
- "coordinates": [
- 11.5811,
- 48.1405
+ [11.58, 48.14],
+ [11.5811, 48.1405]
]
},
"properties": {
"trip": 2,
- "id": 1,
- "accuracy": 6.2,
- "altitude": 0,
- "speed": 0,
- "bearing": 0,
- "battery": 87,
- "battery_status": "Unknown",
- "note": null,
- "time": "2023-11-14T22:31:00.000Z"
+ "accuracy": [5, 6.2],
+ "altitude": [530, 0],
+ "speed": [3, 0],
+ "bearing": [10, 0],
+ "battery": [88, 87],
+ "battery_status": ["Unplugged/Discharging", "Unknown"],
+ "note": [null, null],
+ "time": ["2023-11-14T22:30:00.000Z", "2023-11-14T22:31:00.000Z"]
}
}
]
diff --git a/apps/mobile/src/components/features/settings/MtlsSection.tsx b/apps/mobile/src/components/features/settings/MtlsSection.tsx
index f6bf5a64..3959ca3c 100644
--- a/apps/mobile/src/components/features/settings/MtlsSection.tsx
+++ b/apps/mobile/src/components/features/settings/MtlsSection.tsx
@@ -28,8 +28,7 @@ function errMsg(map: Record<string, string>, err: any, fallback: string): string
}
type ImportState =
- | { kind: "idle" }
- | { kind: "picked"; b64: string; password: string; importing: boolean; error: string | null }
+ { kind: "idle" } | { kind: "picked"; b64: string; password: string; importing: boolean; error: string | null }
export function MtlsSection() {
const { colors } = useTheme()
diff --git a/apps/mobile/src/types/global.ts b/apps/mobile/src/types/global.ts
index 3ac832c8..988c3d82 100644
--- a/apps/mobile/src/types/global.ts
+++ b/apps/mobile/src/types/global.ts
@@ -110,14 +110,7 @@ export type HttpMethod = "POST" | "GET"
export type SyncCondition = "any" | "wifi_any" | "wifi_ssid" | "vpn"
export type ApiTemplateName =
- | "custom"
- | "dawarich"
- | "geopulse"
- | "overland"
- | "owntracks"
- | "phonetrack"
- | "reitti"
- | "traccar"
+ "custom" | "dawarich" | "geopulse" | "overland" | "owntracks" | "phonetrack" | "reitti" | "traccar"
export type DawarichMode = "single" | "batch"
@@ -464,8 +457,7 @@ export type ClientCertInfo = {
export type ClientCertSource = "keychain" | "p12"
export type ClientCertInfoResult =
- | { configured: false }
- | ({ configured: true; error?: string; source?: ClientCertSource } & Partial<ClientCertInfo>)
+ { configured: false } | ({ configured: true; error?: string; source?: ClientCertSource } & Partial<ClientCertInfo>)
export type KeyChainPickResult = Extract<ClientCertInfoResult, { configured: true }>
diff --git a/fastlane/metadata/android/en-US/changelogs/41.txt b/fastlane/metadata/android/en-US/changelogs/41.txt
index 1095cc9b..89c7f2c9 100644
--- a/fastlane/metadata/android/en-US/changelogs/41.txt
+++ b/fastlane/metadata/android/en-US/changelogs/41.txt
@@ -1,2 +1,3 @@
- Share your setup as a link: pick which settings, geofences and profiles to include from the new Share Setup screen in Settings.
- Fixed tracking stopping after an app update.
+- GeoJSON export is now a compact format (~40% smaller) that re-imports into Colota without losing notes or battery status. Older GeoJSON files still import. (breaking)