Use OpenStreetMap data in Mapbox Studio

If you’re looking to use OpenStreetMap data in Mapbox Studio, look no further! This guide will show you how to take advantage of the OpenStreetMap data in the Mapbox Streets tileset, and then how to use Overpass Turbo to query the OpenStreetMap database and extract features within a specific area.

OpenStreetMap features

In OpenStreetMap, contributors can tag physical features like buildings or roads to help describe them.

map features wiki

For example, to add a building tag to a feature you the key for the feature would be building and the value set to yes.

building tag

What type of building is it? Apartment? Farm? Warehouse?

It’s a hotel. We can change the tag to building=hotel to be more specific. Now others who access the data will know that the feature is a building and that it’s a hotel. This is especially helpful for someone who is trying to query all of the hotels in a particular area.

You can find the list of all keys and values on the OpenStreetMap Features wiki.

OpenStreetMap data and Mapbox Streets

If any of this OpenStreetMap data looks familiar, it’s because Mapbox Streets uses OpenStreetMap as its main data source. Mapbox Streets is a vector tileset that is available to all Mapbox users to use when creating map styles with the Mapbox Studio style editor, and it is used in almost all of the Mapbox template styles. If you create a new style based on a Mapbox template, odds are the style includes the Mapbox Streets tileset.

Mapbox Streets is a curated tileset created from OpenStreetMap data, and it is updated with the same frequency that OpenStreetMap is edited (well, almost). But the key word here is curated: Mapbox Streets does not contain 100% of the data that is in OpenStreetMap, but it does contain a lot of it! If you want to use OpenStreetMap data in Mapbox Studio, the quickest and easiest way is to use Mapbox Streets as a source for your style.

Beyond Mapbox Streets: using Overpass Turbo

If you want features on your map that are not included in this tileset, you will want to use additional OpenStreetMap tools to get the data and load it into your Mapbox Studio style. In this guide we will show you how to use Overpass Turbo, an API that allows you to query the OpenStreetMap data set and extract specific features in a given area. Then we’ll take a look at ski lifts and trails at Mt. Bachelor, a popular ski resort in central Oregon. We’ll extract the data for Mt. Bachelor’s ski facilities using Overpass Turbo, style it in the Mapbox Studio style editor, and share it right away.

Let’s get going!

Let's explore

In this exercise, we need to find some of the features at the Mt. Bachelor Ski Resort:

  • Downhill ski slopes
  • Chair lifts
  • Lift stations

First, we need to find the proper tags for these features from the Primary Map Features wiki.

There are two ways to go about finding the features that you want:

  1. Start an edit session in OpenStreetMap and click the feature to find its tags.
  2. Search the Map Features wiki.

Let’s take the second approach and search the wiki. Here, we’ll try to find the keys and values that most closely resemble the features we want to query.

From the wiki, we found the following key and values of our features:

key value element comment
piste:type downhill Area/Way An alpine/downhill ski route. ways should be used for trails connecting the routes. This automatically implies oneway=yes. The direction of the way should be the downhill direction.
aerialway chair_lift Way Looped cable with a series of single chairs (typically seating two or four people, but can be more). Exposed to the open air. This implies oneway=yes. Any two-way chairlifts should be tagged oneway=no.
aerialway station Node Area A station, where passengers can enter and/or leave the aerialway

Now that we have the correct keys and values, let’s hop over to Overpass Turbo to query OpenStreetMap for the data.

Overpass Turbo overview

Let’s take a quick tour of Overpass Turbo’s interface.

Interface menu

  • Run. Runs the current query in the code window. The result is highlighted on the map to the right.
  • Share. Links to the current query.
  • Export. Exports the queried data into different formats for use in other applications.
  • Wizard. A query wizard that allows you to find features based on the keys and their values.
  • Save. Saves your query for future use.
  • Load. Load a sample query or your saved query.
  • Settings. Allows you to change the map background, language, and other features of the interface.
  • Help. Useful hints and topics regarding the interface.

Tabs

  • Map. The default map view (you can swap background with other web services).
  • Data. A raw data view.

Running a query

When you first launch Overpass Turbo, it starts you off with an example for querying drinking fountains. Overpass Turbo uses a query language that is a simplified version of the XML query language.

OT portland

You must click Run for the results to be shown on the map. Once you’ve executed the query, Overpass will highlight the features that satisfy the query.

OT portland drinking fountains

Let’s look closer at the structure of the query:

/*
This is an example Overpass query.
Try it out by pressing the Run button above!
You can find more examples with the Load tool.
*/
node
  [amenity=drinking_water]
  ();
out;

The query starts by looking for features with the type node. Then it checks the key amenity against the value drinking_water. A bounding box (southwest and northeast coordinate pairs) can be issued, or in this case, a {{bbox}} variable will grab the current window’s extent.

Now that you’re familiar with Overpass Turbo’s interface, let’s grab those ski features.

Finding the ski amenities

Let’s start our search by using the search tool to locate mt. bachelor, oregon. The search tool is located on the map to the right of the zoom buttons.

Once you’ve located and zoomed to the Mt. Bachelor, click the Wizard button from the toolbar and paste the following statement in the Wizard:

aerialway=station OR aerialway=chair_lift OR piste:type=downhill

These are the keys and values we found from the Map Features wiki. Click build and run query.

You should see that Overpass has built the query and highlighted the features on the map.

Export data

Now that Overpass has found the features, let’s export them. From the Export button in the toolbar, select GeoJSON. Overpass gives us a ton of options, but we’ll choose geoJSON because the format works well with Mapbox Studio.

OT export

You can also share queries in Overpass from the Share button in the toolbar. This particular query has been saved and is ready to run.

Working with custom data in Mapbox Studio

Now that we have a solid data set to work with, we can upload this directly to Mapbox Studio and create a style using the attributes in our ski data.

Importing data

We are going to make a vector tileset from the GeoJSON file we previously exported from Overpass Turbo. Start by going to your Tilesets tab in Mapbox Studio and select New tileset.

new tileset

The upload process will begin and an uploads pane will appear in the lower left corner of the page. This pane shows the status of your upload, your map ID, and a blue dot as the file is processing.

When the upload is successful, click the tileset to view its details.

tileset details

Click the Add to style button to launch the style editor. Before you do so, however, you must pick whether to add this to an existing style or create one from a template. Let’s create a New Style.

new tileset

Styling data

Once you’ve created the new style, the editor will launch with the New layer tab open and your data ready to add to the map. To add the features as a layer, click Create Layer to add it to the map.

add layer

By default, the editor recognizes the GeoJSON file contain a number of line features so it defaults to a line type geometry. Recall, however, there are also point features you can create styles for so keep this in mind as you create additional layers a little later. Note how all line features are added. For now, let’s filter out just the chair lifts.

add layer

Next, we can set a few styles for our chairlifts - a dark color with a line dasharray of 1,1 and renamed to Ski - chairlifts.

Continue to create more layers and styles based on the attributes in your data set by duplicating your layer.

If you don’t see the attributes you need, you can go to OpenStreetMap and make the edits yourself.

Keep styling!

Next steps

You’ve just learned how to query and export data from Overpass Turbo, upload it to your Mapbox account as a vector tileset, and create a filtered layer for styling in the Mapbox Studio style editor. Here’s a lineup of our other articles and guides that will help you take your work even further:

Ready to share your map? Tweet us @Mapbox and show off your work.

Next article:

Add points to a web map Part 1

Create a new dataset of points

Additional questions? Ask our support team or learn more about How Mapbox Works.