Tutorial7 min readNovember 18, 2024

How to Convert KML to GeoJSON: QGIS, ogr2ogr, and Online Tools

KML is the Google Earth export everyone has and GeoJSON is the web map everyone uses. Three reliable ways to bridge them — and what gets quietly dropped on the way.

Why this conversion comes up

KML files arrive from Google Earth, MyMaps, drone flight plans, hiking apps, and decade-old GIS exports. GeoJSON is the format every web map library reads natively. The conversion is one of the most common in working GIS — and one of the most lossy if you do it wrong.

This guide covers the three reliable methods, with a frank inventory of what does not survive the trip.

Method 1: QGIS (no command line)

QGIS handles KML through the OGR driver shipped with every install.

  1. Drag the file in. Drop the .kml (or .kmz — same driver) onto the QGIS canvas. The layer panel will show one or more sub-layers if the KML uses folders.
  2. Right-click the layer → Export → Save Features As.
  3. In the dialog: Format → GeoJSON, CRS → EPSG:4326 (GeoJSON requires WGS 84), pick a path, click OK.
  4. The new .geojson lands in your working directory.

This is the most forgiving option. QGIS reads multi-layer KML, handles ExtendedData attributes, and exposes options for precision (Layer Options → COORDINATE_PRECISION) and field renaming.

Gotcha: if the KML uses <gx:Track> GPS tracks, QGIS reads them as multi-line geometries with the time and altitude attributes attached as columns. Some viewers don't render this correctly until you split the columns out.

Method 2: ogr2ogr (the one-liner)

For batch jobs, automation, or when QGIS feels heavy:

ogr2ogr -f GeoJSON out.geojson in.kml

That's it. GDAL handles KML and KMZ identically. Add -t_srs EPSG:4326 for safety even though KML is already in WGS 84.

If the source KML has multiple layers (folders), list them:

ogrinfo -so in.kml

to see layer names, then pass the one you want:

ogr2ogr -f GeoJSON tracks.geojson in.kml "Tracks"

To merge all layers into one GeoJSON FeatureCollection, you need a small loop or the -sql flag with UNION ALL.

For KMZ — the zipped variant — just point at the .kmz directly. GDAL unpacks it transparently.

Method 3: browser / online tools

If you don't have QGIS or GDAL, some in-browser converters run the conversion locally with WebAssembly — no upload, no server. GISpo.studio works differently: the conversion runs on an isolated, short-lived GDAL worker (Fly.io, Frankfurt/EU), and your uploaded file is processed in a per-request temporary directory that is deleted in full the moment the conversion finishes — no database, no persistent storage.

The trade-off is the file size ceiling (usually 50–200 MB) and the lack of advanced options. For typical KML files — Google Earth exports, drone logs, walk traces — it's the fastest path.

What gets lost on the way

KML and GeoJSON have different feature sets. The honest inventory:

  • Styling. KML carries <Style> elements with icon URLs, line colours, polygon fills, and label rules. GeoJSON has no styling spec. All visual styling is dropped — your output will be a plain features collection.
  • 3D geometry. KML supports <altitudeMode> (clampToGround, absolute, relativeToGround). GeoJSON keeps Z values in the coordinate array but loses the mode semantics.
  • Time spans. KML <TimeStamp> and <TimeSpan> elements can land as attributes via the OGR driver, but the semantics are lost — they're just strings.
  • Network links. KML supports linked sub-files via <NetworkLink>. These are not followed by the converter; if the parent KML's content lives in linked files, you need to fetch and convert each one.
  • Models and overlays. <Model> (COLLADA references) and <GroundOverlay> (raster images) are not vector features and are silently dropped.
  • Folder hierarchy. KML's nested folder structure flattens. The OGR driver preserves it as either separate layers or a Folder attribute, depending on how the file is read.

What survives

  • All point, line, and polygon geometries, including multi-geometries.
  • Names and descriptions (mapped to name and description attributes).
  • ExtendedData fields (mapped to attribute columns).
  • Coordinates and elevations (Z preserved in the array).

Common errors

  • "Invalid coordinates" on import. KMLs from old Garmin devices sometimes carry empty <coordinates> tags. Open the file in a text editor, search for empty coordinates blocks, delete the placemarks.
  • Cyrillic / Asian characters become garbled. KML is UTF-8 by spec, but exports from older tools sometimes use Windows-1252. If you see mojibake, re-save the source as UTF-8 first.
  • Empty FeatureCollection. Probably means the KML uses NetworkLinks or contains only Models / overlays. Inspect with ogrinfo.

Recommendation

For one-off jobs: a browser-based converter. For repeatable work or anything with multi-layer structure: ogr2ogr. For exploratory analysis where you'll style and re-export anyway: QGIS.

Related Converters

Format References