Converting Shapefiles to TopoJSON

Looker will not be updating this content, nor guarantees that everything is up-to-date. 

Looker uses a format for creating map layers called TopoJSON. TopoJSON stores region data in a compact format appropriate for the web. But, what if we have region data in a shapefile instead of in TopoJSON format?

You can easily create TopoJSON files from many common shapefile formats. This article demonstrates how to convert a shapefile to TopoJSON using a free online tool called Mapshaper 5. For a drawing tool that will let you create a TopoJSON file by hand, check out geojson.io 3.

Note: For pre-built TopoJSON map layers of commonly used shapefiles, see the Looker Map Layers repository in GitHub.


The Workflow

  1. Visit Mapshaper 5, and drag your shape file into the window:
    d7a1a546-fdce-4b1a-a375-452e0ac77afa.png
  2. You'll see a preview of the shape:
    0dbe9644-43f0-41c8-ab43-5b4f038b7f32.png
  3. You can use the info tool to inspect each region in the shapefile to see what properties it contains. This will let you select the correct value for property_key parameter when creating custom map regions in Looker:
    f76d5c65-0a64-477e-b2f6-14b9925afe9c.png
  4. Just press Export and select TopoJSON as the file format:
    90304220-51db-411e-a160-40014f7d4f4f.png

You're done! You now have a TopoJSON file that can be used to create a map layer in Looker. For a detailed guide to creating map layers, check out the Creating Custom Map Regions Help Center article.

Pro Tip: You can also use Mapshaper to simplify (or compress) the region data if it has too much detail. This can improve download times and rendering performance in Looker. For best results, try to keep the resulting TopoJSON under 5 MB.

These examples use a shapefile of U.S. Congressional districts, which you can find here.

Comments
duncanwil
New Member

I have done all of that for several different maps and it works well up to the very last point … saving the output as topojson. It outputs the code as a .json file and when I get to Power BI to create my custom map all it does is to create an outline map but with none of the detail.

That means I cannot use my data with such maps in Power BI. I did get a .topojson file from another source and that worked well.

Any advice or guidance for me?

Version history
Last update:
‎05-12-2022 02:28 PM
Updated by: