Converting GeoJSON to KML is a common requirement for anyone working with geospatial data across different platforms. GeoJSON is the preferred format for web mapping libraries, but KML remains the standard for Google Earth, Google Maps, and many desktop GIS applications that expect rich, styled geographic content. Whether you need to share a dataset with stakeholders who rely on Google Earth, embed geographic layers in a presentation, or distribute styled map data to field teams, converting from GeoJSON to KML is straightforward with the right tools. This guide covers multiple conversion methods — from browser-based tools to command-line utilities and Python libraries — along with practical tips for handling edge cases during the process.
Why Convert GeoJSON to KML?
GeoJSON and KML serve different ecosystems. GeoJSON is lightweight, JSON-based, and designed for web APIs and JavaScript mapping libraries such as Leaflet and OpenLayers. KML, defined by the Open Geospatial Consortium (OGC), is XML-based and tightly integrated with Google Earth and Google Maps. Converting GeoJSON to KML is useful when you need to:
- Visualize data in Google Earth — Google Earth Pro and the web version natively open KML files, enabling 3D terrain views, time-based animations, and flyovers that GeoJSON alone cannot provide.
- Share with non-technical users — KML files can be emailed and opened with a double-click in Google Earth, making them accessible to audiences who do not work with code or web mapping platforms.
- Leverage KML styling — KML supports inline icon styles, line colors, polygon fills, label scaling, and balloon pop-ups described directly in the file, which GeoJSON does not support natively.
- Integrate with legacy systems — Many government agencies, defense platforms, and enterprise GIS workflows still rely on KML/KMZ for data exchange.
Convert GeoJSON to KML Using GeoDataTools
The fastest way to convert a GeoJSON file to KML without installing any software is to use the GeoDataTools GeoJSON-to-KML converter. The conversion runs entirely in your browser, so your data never leaves your device.
- Open the GeoDataTools application or go directly to the conversion tool page.
- Drag and drop your
.geojsonfile onto the upload area, or click to browse your file system. - The tool parses the GeoJSON, displays a preview on an interactive map, and lists all features with their properties.
- Review the data. Use the built-in filter to exclude features you do not need in the output.
- Click Export as KML. The tool converts each Feature into a KML Placemark, maps properties to ExtendedData, and generates a valid KML document.
- Download the resulting
.kmlfile and open it in Google Earth or any KML-compatible application.
This method works well for files up to several megabytes. For very large datasets or automated pipelines, consider the command-line and scripting approaches below.
Convert GeoJSON to KML with ogr2ogr
ogr2ogr is the Swiss-army knife of geospatial format conversion. It is part of the GDAL/OGR library suite and supports over 80 vector and raster formats. To convert a GeoJSON file to KML from the terminal:
ogr2ogr -f "KML" output.kml input.geojson
This single command reads the GeoJSON, reprojects coordinates to WGS 84 if needed, and writes a well-formed KML file. You can add options to control the output:
# Convert only features matching a SQL filter
ogr2ogr -f "KML" filtered.kml input.geojson -sql "SELECT * FROM input WHERE population > 100000"
# Reproject from EPSG:3857 to WGS 84 during conversion
ogr2ogr -f "KML" output.kml input.geojson -s_srs EPSG:3857 -t_srs EPSG:4326
# Output as compressed KMZ
ogr2ogr -f "LIBKML" output.kmz input.geojson
Install GDAL on Ubuntu with sudo apt install gdal-bin, on macOS with brew install gdal, or on Windows through the OSGeo4W installer. ogr2ogr is ideal for batch processing, CI/CD pipelines, and scripting automated workflows.
Convert GeoJSON to KML with Python
Python offers several libraries for programmatic GeoJSON-to-KML conversion. Two popular approaches use Fiona with manual KML writing or GeoPandas with the GDAL driver.
Using GeoPandas
import geopandas as gpd
gdf = gpd.read_file("input.geojson")
gdf.to_file("output.kml", driver="KML")
GeoPandas delegates the format conversion to GDAL under the hood. It preserves all attribute columns as KML ExtendedData fields. Make sure the GDAL KML or LIBKML driver is available in your environment; you can verify with import fiona; print(fiona.supported_drivers).
Using Fiona
import fiona
src = fiona.open("input.geojson", "r")
schema = src.schema
with fiona.open("output.kml", "w", driver="KML", schema=schema) as dst:
for feature in src:
dst.write(feature)
src.close()
Fiona gives you fine-grained control over the conversion loop, allowing you to transform, filter, or enrich features before writing. Both methods require the GDAL C library installed on your system alongside the Python bindings.
What Converts and What Does Not
GeoJSON and KML overlap significantly, but each format has capabilities the other lacks. The table below summarizes how common elements map between the two formats.
| Element | GeoJSON | KML | Converts? |
|---|---|---|---|
| Point / MultiPoint | Yes | Yes (Placemark) | Yes |
| LineString / MultiLineString | Yes | Yes (Placemark) | Yes |
| Polygon / MultiPolygon | Yes | Yes (Placemark) | Yes |
| GeometryCollection | Yes | MultiGeometry | Yes |
| Properties / attributes | JSON object | ExtendedData | Yes |
| CRS / projection | WGS 84 (EPSG:4326) | WGS 84 | Yes |
| Inline styling | Not supported | Style, IconStyle | No (must add manually) |
| 3D coordinates | Optional altitude | altitudeMode | Partial |
| Time data | As properties | TimeSpan / TimeStamp | No (must map manually) |
| Network links | Not supported | NetworkLink | No |
For a deeper comparison of these two formats, see the GeoJSON vs KML comparison guide.
Tips for Clean Conversions
- Validate your GeoJSON first. Malformed coordinates or missing geometry fields cause silent errors during conversion. Use a GeoJSON validator before converting.
- Check coordinate order. GeoJSON uses [longitude, latitude] per RFC 7946. KML expects longitude, latitude, altitude. Most tools handle this automatically, but manual scripts can swap coordinates if not careful.
- Keep property names simple. KML ExtendedData names must be valid XML identifiers. Avoid property keys with spaces, special characters, or leading numbers.
- Add styling after conversion. Since GeoJSON has no styling model, apply icon styles, line colors, and polygon fills in the KML file after conversion or post-process with a KML editor.
- Test with Google Earth. Always open the resulting KML file in Google Earth to verify geometry placement, pop-up content, and attribute rendering before distributing the file.
- Consider KMZ for distribution. KMZ is a zipped KML that can include icons and overlay images. Use
ogr2ogr -f "LIBKML"or zip the KML manually for smaller file sizes and self-contained packages.
FAQ
Can I convert GeoJSON to KML without installing software?
Yes. Browser-based tools like GeoDataTools perform the conversion entirely in your browser using JavaScript. Upload your GeoJSON file, preview the data on a map, and download the KML output. No server upload, no installation required.
Does the conversion preserve all GeoJSON properties?
Standard conversion tools map GeoJSON feature properties to KML ExtendedData elements, so attribute names and values are preserved. However, nested JSON objects or arrays inside properties may be serialized as strings rather than structured KML data, depending on the tool.
What is the difference between KML and KMZ?
KML is a plain-text XML file. KMZ is a ZIP archive containing one or more KML files along with supporting resources such as custom icons, overlay images, or model files. KMZ files are smaller and self-contained, making them better for distribution. Most tools that read KML also accept KMZ.