Guides & How-tos

Moving Map Data Between GeoJSON, KML and GPX

Your watch exports GPX, Google Earth wants KML, and every mapping library wants GeoJSON. Here is how to move between them locally, and which details quietly disappear on the way.

Guides & How-tosUpdated Version 1.04 min readNovus Convert Team
A GPS track converting between GPX, KML and GeoJSON inside a browser window, with the coordinates staying on the device.

Geospatial files are a small world with strong opinions. A GPS watch writes GPX. Google Earth reads KML. Every web mapping library on the planet wants GeoJSON. Surveyors send shapefiles. All four describe points and lines on the Earth, and none of them agree on how.

Converting between them is usually quick. Knowing what does not survive is the part worth reading, because location data has a habit of losing exactly the field you needed.

What each format is actually for#

  • GeoJSON is plain JSON with a geographic shape. It is the lingua franca of web mapping, it always uses WGS 84 longitude and latitude, and it carries arbitrary properties on each feature.
  • KML is Google's XML format. It carries presentation as well as geometry: icons, colours, styles and folder structure, which is why an exported map looks like the map you made.
  • GPX is the GPS exchange format. It thinks in waypoints, routes and tracks, and it carries timestamps and elevation because a recorded track is a thing that happened rather than a shape.
  • Shapefile is the long-standing GIS format, and it is not one file. It is several that must travel together, which is the single most common reason one fails to open.

The conversions people actually need#

To put a recorded route on a web map, convert GPX to GeoJSON. To open web map data in Google Earth, convert GeoJSON to KML. To take something out of Google Earth and into code, convert KML to GeoJSON. Each runs in the browser, which for location data is not a minor detail.

What gets lost, and why#

Styling, when leaving KML#

KML carries icons, line colours and fill styles. GeoJSON has no opinion about appearance at all: it describes geometry and properties and leaves rendering to whatever draws the map. Converting KML to GeoJSON therefore keeps the shapes and drops the look, which is correct behaviour and still a surprise the first time.

Time and elevation, when leaving GPX#

A GPX track point usually carries a timestamp and an elevation. GeoJSON can hold both as properties, but whatever consumes the file has to know to look for them. If a downstream tool shows a flat, timeless line, the data is often still in the file and simply unread.

Coordinate systems, when leaving a shapefile#

GeoJSON is defined in WGS 84. A shapefile may be in a national grid or a projected system entirely. If converted points land in the sea or in another country, the source was projected and needs reprojecting rather than reconverting.

Before you send it on#

  1. Open the output on a map and confirm the shape is where you expect, not merely that a file exists.
  2. Count the features. A converted file with fewer points than the original lost something.
  3. Check one feature's properties by hand and confirm the fields you care about came through.
  4. For a shapefile, confirm every sidecar file travelled with it before blaming the conversion.

For the general version of that discipline, see verifying conversion results.

Troubleshooting

Points appear in the wrong part of the world

The source used a projected coordinate system rather than WGS 84 longitude and latitude. Reproject it in a GIS tool before converting; a converter cannot infer the original projection.

The map lost all its colours and icons

Expected when leaving KML. GeoJSON describes geometry and properties, not appearance. Restyle in whatever renders the map.

A shapefile will not open

A shapefile is several files that must stay together. Supply the complete set rather than the .shp alone.

Elevation or timestamps look missing

They are usually present as feature properties and simply unread by the receiving tool. Inspect one feature in a text editor before concluding the data was dropped.

Frequently asked questions

Which format should I use for a web map?

GeoJSON. Every mainstream web mapping library reads it directly, it is plain JSON so it is easy to inspect, and it is always in WGS 84 longitude and latitude.

Why did my styling disappear converting KML to GeoJSON?

GeoJSON has no styling model. It describes geometry and properties and leaves appearance entirely to the renderer. The shapes are intact; the look has to be reapplied where the map is drawn.

Can I convert a shapefile here?

Yes, to GeoJSON, provided you supply the complete set of sidecar files. A shapefile is not a single file, and the .shp alone is missing the attributes and the projection.

Is my GPS track uploaded anywhere?

No. The conversion runs entirely in your browser. That matters more here than for most files, because a track from a watch is a minute-by-minute record of where a specific person was.

Does converting remove personal information from a track?

No. Converting changes the container, not the contents. If a track starts at your home address, it still does afterwards. Trim the start and end in a mapping tool before sharing.

Related workflows and tools

Sources and further reading