Skip to content

Tutorial: Combining two layers

Amanda Hickman edited this page Apr 11, 2019 · 4 revisions

This walk through will help you combine and prune two layers to output a GeoJSON basemap that you can import into Datawrapper for use as a basemap.

A bit of context

Datawrapper will let you use any boundary file as a basemap, but it has to be in TopoJSON or GeoJSON format, and meet a few other requirements.

I wanted to create a basemap of Bay Area counties so I could use datawrapper for more local maps. That meant I was going to need to find a basemap, cut out the areas beyond the Bay Area, and convert it to a supported JSON format.

I started at the Californa Open Data Portal, where the state makes US Census county, State and place boundary files available. Unfortunately, these boundary files aren't clipped to the shoreline. So while they're technically accurate, they're not going to resonate with someone who is used to looking at maps of land.

tiger_counties.png

There are a few ways I could go about clipping the legal boundaries to the shoreline, but the easiest was to search for a map that was already clipped to the shoreline. Luckily, Cal's library maintains their own Geo Data commons and it includes a boundary file that is clipped to the shoreline.

cal_counties.png

I wanted a layer that would show us the actual boundaries of Alameda County cities, too. The library's Places boundary file includes those.

Enter Mapshaper

First, download the .zip files, and upload them to Mapshaper's web interface.

Based on Datawrapper's instructions for transforming maps, your next steps are these:

On each layer set the projection with proj wgs84 -- just open the sidebar console and type that command in. Note: I ran proj wgs84 twice, once with each layer selected. There might be a way to apply the command to multiple layers.

» proj command reference

Clipping layers

The data in california_place_clipped is statewide, so we need to drop the places that are outside of the bay area.

With california_place_clipped selected, run clip bayarea_county to drop all places outside of Bay Area Counties.

» clip command reference

Alternatively, a filter would work, since california_place_clipped includes a "County" field:

filter '"Marin, Contra Costa, Alameda, San Francisco, Santa Clara, San Mateo".indexOf(COUNTY) > -1'

» filter command reference

Merge the layers

The data is still stored in two layers. To merge the layers into a single boundary file, use:

merge-layers target=bayarea_county,california_place_clipped force

Learning Opportunity: try the command without the force flag and see if you can sort out what force is doing!

» merge-layers command reference

Now what?

Now you can export the combined layer as a single GeoJSON file. In a future tutorial we'll play with adding place labels.