[openstreetmap/openstreetmap-website] Traces KML upload (Issue #6873)

Soubhagya Sadhukhan notifications at github.com
Wed Mar 11 11:21:34 UTC 2026


notlevi911 left a comment (openstreetmap/openstreetmap-website#6873)

Add KML file support for GPS trace uploads**

Fixes the inability to upload GPS traces exported as KML files (e.g. from Traccar, Google Earth, and similar tools).

### Problem

Users with GPS trackers that export KML files (such as Traccar) could not upload their traces. Only GPX and compressed GPX formats were supported.

### Changes

**`lib/gpx.rb`**
- Added `parse_kml_file` — a streaming XML parser that handles two KML track formats:
  - `<Placemark><LineString><coordinates>` (Traccar-style) — coordinates are in `lon,lat,alt` format with no per-point timestamps; synthetic timestamps 1 second apart are assigned, with the start time extracted from the Placemark `<name>` field (e.g. `"2026-03-09 22:00 - 2026-03-10 21:59"`) or falling back to Unix epoch
  - `<gx:Track>` (Google Earth) — pairs `<when>` ISO-8601 timestamps with `<gx:coord>` values for real timestamps
- Added `kml_data?` / `kml_file?` helpers that detect KML by peeking at the first 1 KB for the `http://www.opengis.net/kml` namespace
- Updated `points` to route KML files through the new parser (works for plain files and files inside zip/tar archives)

**`app/models/trace.rb`**
- `content_type`: plain XML files are now inspected to distinguish KML (`application/vnd.google-earth.kml+xml`) from GPX (`application/gpx+xml`)
- `extension_name`: KML files are saved with `.kml` extension
- Added private `kml_file?` helper

**`app/views/traces/new.html.erb`**
- Added `.kml` to the accepted formats hint on the upload form

**Tests**
- `test/gpx/fixtures/k.kml` — Traccar-style LineString fixture
- `test/gpx/fixtures/l.kml` — Google Earth `gx:Track` fixture  
- `test/lib/gpx_test.rb` — 30+ unit tests covering coordinate parsing, lon/lat swap, altitude, synthetic vs real timestamps, fallback to epoch, out-of-range rejection, `FileTooBigError`, multiple placemarks, and KML detection
- `test/models/trace_test.rb` — integration tests for KML import, MIME type, and extension detection
- `test/factories/traces.rb` — added `fixture_ext` transient to support non-GPX fixture files

### Example KML (Traccar)

```openstreetmap-website/test/gpx/fixtures/k.kml#L1-15
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>Test Device</name>
    <Placemark>
      <name>2008-10-01 10:10 - 2008-10-01 10:10</name>
      <LineString>
        <extrude>1</extrude>
        <tessellate>1</tessellate>
        <altitudeMode>absolute</altitudeMode>
        <coordinates>1.0,1.0,134.0 1.0,1.0,134.0</coordinates>
      </LineString>
    </Placemark>
  </Document>
</kml>

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/issues/6873#issuecomment-4038519083
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/issues/6873/4038519083 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20260311/20fd1a0f/attachment.htm>


More information about the rails-dev mailing list