GeoSlides
Market: United States
Browse templates
Home/ Guides/ GeoJSON vs Shapefile vs KML: Which File Should You Send?

Map data·5 min read

GeoJSON vs Shapefile vs KML: Which File Should You Send?

GeoJSON is one text file you can open in Notepad, a shapefile is a set of binary files you cannot, and KML is XML that also knows what color a state should be. Send GeoJSON when a script or a person will read it, a shapefile when a GIS will open it, KML when the destination is Google Earth — and stop using file size to decide.

A monochrome outline map of the United States with state boundaries and no fills
The same 56 state polygons, written three different ways. The geometry does not change; the container does.

The short answer, one line per format

The format is chosen by the software on the other end, not by the specification:

  • GeoJSON — one UTF-8 text file, longitude and latitude only, attributes as a JSON object per feature. Send it when a script, a web map, or a human with a text editor will read it.
  • Shapefile — three or four binary files that share one basename. Send it when the recipient opens ArcGIS or QGIS for a living; it is still the format nobody refuses.
  • KML — one XML file, or a zipped .kmz. Send it when the destination is Google Earth, because the styling is the only thing it does better.

All three can describe the identical 56 state polygons. Only one of them can be opened, read, and diffed on a laptop with no GIS installed, and that is GeoJSON.

GeoJSON vs shapefile vs KML, side by side

GeoJSONShapefileKML
ContainerOne .geojson text file.shp + .shx + .dbf, plus .prjOne .kml, or a zipped .kmz
GeometryNested arrays of [lon, lat]Variable-length records in .shp<coordinates> text: lon,lat,alt
Attributesproperties object, real types.dbf table, 10-character names, no NULL<ExtendedData>, every value a string
Coordinate systemWGS84 only, required by the specAnything, declared in .prjWGS84 only, required by the spec
StylingNone at allNone at all<Style>: fill, outline, icon, balloon
Readable in a text editorYesNoYes, if XML does not bother you
StandardRFC 7946, 2016Esri, 1998 (open spec)OGC KML, 2008

Two rows settle most arguments. Coordinate system: a shapefile can hold State Plane feet or Web Mercator meters; GeoJSON and KML cannot hold anything but WGS84 decimal degrees, so a projected layer has to be reprojected before it can be written as either. Styling: KML is the only one of the three that knows a polygon is supposed to be dark red.

Read the first 120 characters of a real file

This is the opening of a national state boundary file, byte for byte, nothing removed:

from pathlib import Path

text = Path("us_state.geojson").read_text(encoding="utf-8")
print(text[:120])
print(text.count("\n"), "newlines")
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"STATEFP":"21","STATENS":"01779786","GEOIDFQ":"0
0 newlines

Fifty-six states and territories, 2,296,016 bytes, and not one newline in the file. read_text() gives back a string of 2.3 million characters because every character in it is ASCII. Nothing in the file is addressed by line number, so every editor that opens it will pause, and every reader will spend its time parsing rather than seeking.

That is a real difference from the binary format, not a cosmetic one. A shapefile starts with a 100-byte header that states the file length, so a truncated download can be detected before reading a single shape. GeoJSON has no header, no magic number, and no length field: a truncated file is simply invalid JSON, and the parser's complaint will point at whatever character it happened to be on. Truncation is easier to diagnose in the binary format, and easier to work around in the text one.

The rules that make a file valid GeoJSON are short, and RFC 7946 is worth reading once:

  1. Coordinates are WGS84 decimal degrees, longitude first. A shapefile carries its own projection; GeoJSON cannot, so -122.4, 37.8 is the only shape a coordinate is allowed to take.
  2. The crs member is gone. Files from older exporters still carry "crs": {"type": "name", ...} and readers ignore it — reproject before export instead of hoping.
  3. An exterior ring runs counterclockwise, holes run clockwise. Get this backwards and a fill test will think the state is the hole.
  4. Right-hand rule aside, the whole thing is one JSON object. type is FeatureCollection, and every feature has properties and geometry, in that order by convention.

What KML does that the other two cannot

KML's <Placemark> is a place, not a row. It has a <name> that shows in the Google Earth sidebar, a <description> that opens as a balloon on click, and a <Style> that can set fill color, outline width, and label size. Folders group placemarks into a tree you can check on and off. None of that exists in GeoJSON — a web map decides styling in JavaScript, and a shapefile gets its colors from a separate .lyr or QML file that travels beside it if you remember to send it.

Two details trip people up when they hand-write or patch a KML:

  • Coordinates are lon,lat,alt triples separated by whitespace inside one <coordinates> element, not a nested array. That is why a KML of the county layer is a single very long line of numbers.
  • A .kmz is a zip archive containing doc.kml and any icons. It is not a different format, and renaming a .kmz to .kml gives you a file no parser will read.

KML is also the format that survives a round trip through Google Earth's "Save place as" without losing its colors, which is exactly the case where its verbosity pays for itself.

Size on disk, measured on the same 56 polygons

Everyone assumes KML is the fat one. Measured on the state layer above, it is the smallest of the three:

Rendering of the same 56 polygonsBytesGzipped
GeoJSON as published, 13 decimal places2,296,016829,050
GeoJSON rounded to 5 decimals1,948,909634,705
KML, 5 decimals, geometry only1,784,378620,154

The layer holds 91,888 vertices, so the raw file spends 25 bytes per vertex. Rounding every coordinate to five decimal places — about 1.1 meters, far below the width of a state line on a slide — removes 347,107 bytes, 15 percent, without moving a boundary anywhere a reader could see. That is a bigger effect than the choice of format.

import gzip, json
from pathlib import Path

src = Path("us_state.geojson")
data = json.loads(src.read_text(encoding="utf-8"))

def r5(geom):
    def walk(c):
        return [round(c[0], 5), round(c[1], 5)] if isinstance(c[0], (int, float)) else [walk(x) for x in c]
    return {"type": geom["type"], "coordinates": walk(geom["coordinates"])}

compact = {"type": "FeatureCollection",
           "features": [{"type": "Feature",
                         "properties": f["properties"],
                         "geometry": r5(f["geometry"])} for f in data["features"]]}
raw = json.dumps(compact, separators=(",", ":")).encode("utf-8")

print(src.stat().st_size, len(raw), len(gzip.compress(raw, 9)))
# 2296016 1948909 634705

KML compresses better than GeoJSON — 620,154 bytes against 634,705 — because XML repeats the same tag names tens of thousands of times and repetition is what gzip eats. Over the wire, with compression on, the two formats land within 2 percent of each other. Size stopped being a reason to pick one years ago; what is left is which software can open it.

Converting without losing the GEOID

GDAL does all six conversions and is one install away (brew install gdal, or the OSGeo4W installer on Windows):

ogr2ogr -f GeoJSON states.geojson us_state.shp -lco RFC7946=YES
ogr2ogr -f KML states.kml us_state.shp
ogr2ogr -f "ESRI Shapefile" roundtrip states.geojson

The RFC7946=YES flag matters. Without it, GDAL writes the deprecated crs member and leaves coordinates in whatever projection the source used; with it, you get WGS84 and a file that any web map will accept without complaint.

The lossy step is never the geometry, it is the attribute table:

Moving from → toWhat happens to GEOID
Shapefile → GeoJSONText stays text. 01001 survives intact
GeoJSON → shapefileField names truncate at 10 characters, values survive
Anything → KMLEvery value becomes a string; numbers come back as text
Either → spreadsheet → backLeading zeros die, and 01001 becomes 1001

A KML round trip turns ALAND from an integer into the string "102267794436", and nothing in the file records that it used to be a number. If the attributes are going to be joined to anything downstream, convert to GeoJSON or shapefile and leave KML for the map you are about to look at. What the codes themselves mean is the companion piece to this one; the shapefile breakdown explains why its table has those limits in the first place.

Why none of the three opens in PowerPoint

There is no import path from any of these formats into a slide. PowerPoint will take an SVG, and an SVG has no attribute table, so a boundary file has to be converted to native shapes with the names attached before a deck can use it — one shape per polygon, NAME from the properties beside it. That conversion is the whole product: the state map is 56 editable shapes, and the county map is the same idea at 3,235.

A slate gray map of the United States with all fifty states and D.C. drawn as separate shapes
What the boundary file turns into after conversion: 56 shapes, one fill, no .prj left to lose and no attribute table to join.
Is GeoJSON better than a shapefile?
It is more readable and it is one file, which makes it better for scripts, web maps, and version control. A shapefile is better when the recipient needs a projection other than WGS84, or when the attribute table has numbers that must stay numbers.
Can I just rename a .kml to .kmz?
No. A .kmz is a zip archive that contains doc.kml plus any icons, so renaming gives you a zip that nothing will open as KML. Zip the doc.kml to make one, or export from Google Earth.
Does GeoJSON support projection?
Not in RFC 7946. Coordinates are WGS84 decimal degrees by definition, and the old crs member was removed in 2016. Reproject the source before exporting.
Which format should I send for a slide deck?
None of them directly. All three must be converted to native shapes or vector art first, because PowerPoint has no boundary-file import and an SVG carries no attribute table.

Skip the conversion

Every state and county arrives as an editable polygon with its name and code already attached — no GDAL, no reprojection, no missing .prj.

See the state map

Questions

Is GeoJSON better than a shapefile?
It is more readable and it is one file, which makes it better for scripts, web maps, and version control. A shapefile is better when the recipient needs a projection other than WGS84, or when the attribute table has numbers that must stay numbers.
Can I just rename a .kml to .kmz?
No. A .kmz is a zip archive that contains doc.kml plus any icons, so renaming gives you a zip that nothing will open as KML. Zip the doc.kml to make one, or export from Google Earth.
Does GeoJSON support projection?
Not in RFC 7946. Coordinates are WGS84 decimal degrees by definition, and the old crs member was removed in 2016. Reproject the source before exporting.
Which format should I send for a slide deck?
None of them directly. All three must be converted to native shapes or vector art first, because PowerPoint has no boundary-file import and an SVG carries no attribute table.

Written in-house. Boundary counts are checked against the published files, and every figure on this page can be reproduced from the source named in it.

Keep reading