Skip to main content

How to convert Shapefiles to GeoJSON maps for use on GitHub (and why you should)

3 min read
: A step-by-step guide to converting ESRI Shapefiles to GeoJSON format for rendering as interactive maps on GitHub, plus why open formats matter for public data.
Table of contents

With GitHub natively supporting mapping and embeds, I recently wanted to put some of the free, publicly available government data published on data.dc.gov to use. They have all sorts of great information, from bus routes to polling places, to the location of every liquor license in DC. The only problem was that the data was stored in a proprietary and complex format known as a Shapefile which arose in an age when the desktop ruled supreme and requires a costly software subscription for many common uses.

Luckily, a strangely named piece of open source software known as ogr2ogr can convert the data into the more modern, more open GeoJSON format that GitHub supports, and the resulting map can be automatically rendered, not to mention more easily diffed.

If you’ve got a Mac, it only takes a few seconds#

  1. If you don’t already have it, install Homebrew by opening up terminal and running: $ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
  2. Install gdal with the command: $ brew install gdal
  3. Grab a Shapefile (distributed as a .zip file) from the DC Data Catalog or your favorite data source and unzip it someplace convenient
  4. cd into the directory with your shiny new unzipped Shapefile
  5. Run (replacing [name] with the name of your downloaded Shapefile): $ ogr2ogr -f GeoJSON -t_srs crs:84 [name].geojson [name].shp
  6. Grab the resulting GeoJSON file and commit it to GitHub
  7. Navigate to the GeoJSON file on GitHub.com to browse your map

In addition converting the Shapefile over to GeoJSON, the other step in there, -t_srs crs:84, ensures that by the time the data hits GitHub, it’s encoded with the right projection so it can be mapped properly. Need to convert multiple Shapefiles in bulk? Just use this bulk Shapefile to GeoJSON conversion script. Windows users? You’re covered too.

Why’s this is important#

For one, you’re liberating public geodata that would otherwise be inaccessible to the average citizen and making it available in a dumb-simple point, click, zoom interface that anyone can use. For another, by putting the information on GitHub in an open, text-based format, civic hackers and subject-matter experts can begin treating that data like open source code — forking, merging, diffing, tracking changes over time — and all of a sudden we’ve opened up not just the data, but the entire collaborative ecosystem that now surrounds it.

The result#

View the DC Embassies map on GitHub.

Originally published June 26, 2013 View revision history
Share

More to explore

That's not how the internet works

7 min read

Stop publishing monolithic datasets. Treat your GitHub repo like a RESTful API — granular, URL-addressable, and optimized for consumers.

Bet on the little guy

3 min read

On the internet, simple and open formats always win. From HTTP to JSON to Markdown, the lightweight underdog consistently beats its proprietary rival.

The technology's the easy part

6 min read

In government IT, technology is never the hard part. Culture is. Stop building new tools and start sustaining the ones you already have.

Intro to GitHub for non-technical roles

10 min read

GitHub isn't just for developers. A practical guide for non-technical roles to follow along, collaborate, and track work with confidence.

How to run LanguageTool on macOS

6 min read

Set up LanguageTool as a free, open-source Grammarly alternative that runs locally on your Mac. No subscription required.

Ben Balter

I'm Ben Balter — I write here about engineering leadership, open source, and showing your work. I was the Director of Hubber Enablement at GitHub, where I helped thousands of GitHubbers do their best remote work. Before this role: Chief of Staff for Security, enterprise PM, and GitHub's first Government Evangelist. Before GitHub: attorney, Presidential Innovation Fellow, and member of the White House's first agile development team. More about the author →

Follow along: Bluesky LinkedIn

This page is open source Help improve this article on GitHub