mapshaper layers merged Einstein Analytics

Custom map in Einstein Analytics with GeoJSON

Sometimes you come into a situation where the maps provided in Einstein Analytics are not matching your requirements and you want to create your own map. Luckily you can upload your own GeoJSON files to use as maps in Einstein Analytics.

Let’s say your business is focused on the US, Canada, and Mexico and you want to see the different states or provinces in those countries when you plot your location via latitude and longitude. At the same time, you are doing business around the world but you don’t necessarily want to see the state lines in those. To make it easy for the user you want to integrate the different levels of information in only one map as shown below.

Uploaded custom map in Einstein Analytics with additional state/province lines for US + Canada

So how can we do this? At first, we need to find a GeoJSON world map as a basic map. There are plenty of good resources out there like mapstarter.com.

How to leverage mapshaper.com to merge map layers?

In the next step you simply import this GeoJSON in mapshaper.com an online tool to edit Shapefile, GeoJSON and TopoJSON formats.

GeoJSON world map

At this point, the world map is not providing the required granularity. For the US and Canada, we want to see the states/province lines. Mapshaper can help us with this as it is able to merge different GeoJSON. All we need to do is to look for the GeoJSON with the correct state lines. Mapstarter can help us here again.

Prep your files

First preparation step is to get rid of the countries in the world map which we want to replace by the country maps with more detailed information

For this, we need to open the world map JSON in an editor (e.g. Sublime ) to look up the property name with we need later in mapshaper.

In this example I was searching for the USA and I can see that the “NAME” property is “United States”. I will use this information now in the map shaper console (on the top right) and drop/filter for the USA from the GeoJSON.


 $ filter 'NAME != "United States"'

With this simple code snippet, I can delete the USA borders from the world map. I’m going to do the same for Canada and the world map is changing accordingly by indicating the deleted/filtered countries in green.

Merge map layers

To fill in the gaps for the US and Canada we need to import new GeoJSON’s with the required level of detail. Mapshaper allows us to simply drag and drop both files on top of the canvas. In the dropdown menu on top with the down arrow I can select which map layer I want to make visible. Here I select all 3 layers, world, US_States and Canada.

Now we can check the details in the maps and verify that the layers fit in the boarders where the different maps are touching are aligned.

In the final step we need to merge those 3 layers with the merge-layers feature from mapshaper. The layers which we want to merge are defined in the “target” parameter. More information how map layers can be merged can be found here.


$ merge-layers target=canada,US-States,world force

With this the map layers are merged and the final map can be exported as GeoJSON on the top right under “Export”. Simply choose the export format GeoJSON.

Now we can import the new map in Einstein Analytics via the custom map upload and use it as we would use any of the default maps where we leverage latitude and longitude data points.

Another example with custom GeoJSON and how to create shapes from scratch can be found here.

Resources

Mapshaper http://mapshaper.org

Mapshaper command reference

https://github.com/mbloch/mapshaper/wiki/Command-Reference

GeoJSON World, US + Canada with state lines/ province lines

http://mapstarter.com

Salesforce custom maps video

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.