Learn

Shapefile to GeoJSON: three ways to convert

A Shapefile is a set of at least four binary files (.shp, .dbf, .shx, .prj). GeoJSON is a single JSON file. Converting between them is a one-command operation once you know which tool to use.

What to know before converting

  • Projection: Shapefiles store their coordinate reference system in the .prj file. GeoJSON must use WGS 84 (EPSG:4326). If your Shapefile is in any other CRS — British National Grid, UTM zones, State Plane — the reproject step is not optional.
  • Field name length: Shapefile attribute names are capped at 10 characters. A field named population_density becomes population in the output, silently.
  • Multi-part features: Multi-part geometries in a Shapefile (a single record with disconnected parts) become MultiPolygon or MultiLineString Features in GeoJSON automatically.

Method 1: QGIS

No command line required. Works on Windows, macOS, and Linux.

  1. Open QGIS. Drag the .shp file onto the canvas.
  2. Right-click the layer in the Layers panel → Export → Save Features As.
  3. Set Format to GeoJSON. Set CRS to EPSG:4326 — WGS 84.
  4. Choose an output file path. Click OK.

QGIS reprojects the data automatically when you select EPSG:4326, so you don't need to match the source projection first.

Method 2: ogr2ogr

ogr2ogr is part of GDAL. Install it with:

brew install gdal       # macOS
apt install gdal-bin    # Debian / Ubuntu

Convert with one command:

ogr2ogr \
  -f GeoJSON \
  -t_srs EPSG:4326 \
  output.geojson \
  input.shp

Flag breakdown:

  • -f GeoJSON — output format
  • -t_srs EPSG:4326 — target spatial reference system; reprojects from the source CRS regardless of what the .prj file contains
  • output.geojson — output file path
  • input.shp — input file path

This is the fastest method for automation. It runs in milliseconds on small datasets and handles files too large to open in QGIS without issue.

Method 3: Python with geopandas

Use this inside a data pipeline that already runs Python.

import geopandas as gpd

gdf = gpd.read_file("input.shp")
gdf_wgs84 = gdf.to_crs(epsg=4326)
gdf_wgs84.to_file("output.geojson", driver="GeoJSON")

geopandas also accepts .zip archives that contain a Shapefile — useful when downloading data from government portals that bundle all four files in a zip.

Install geopandas with pip install geopandas. On macOS, GDAL must be installed first (brew install gdal).

What gets preserved

PropertyPreserved?Notes
Geometry types✓Multi-part geometries become Multi* types
Attribute fields✓Field names truncated to 10 characters
Coordinate precision✓Full double-precision floats in GeoJSON
Feature count✓One-to-one mapping
Projection×Always converted to WGS 84 (EPSG:4326)
Layer name×Lost; only the geometry and attributes survive

Watch out: If the Shapefile is in a local CRS (e.g. OSGB 1936 / British National Grid, EPSG:27700), coordinates in the GeoJSON will be wrong — often by thousands of metres — unless you include the reproject step. Always check the .prj file before converting.

For GeoJSON format reference, see What is GeoJSON?. For more Python GeoJSON patterns, see GeoJSON with Python.

Once converted, you can open the GeoJSON file in Element Editor's playground to inspect and edit the features visually.

Continue reading

Mike Acler

Mike Acler

Design engineer and creator of Element Editor, an open-source map drawing and GeoJSON editing library for React. Writes about web cartography and GIS tooling.