If you have been playing around with the new Mapbox Studio you might be interested to know how to make a custom map with objects of your own interest from OpenStreetMap.
To make the process of creating an updating an OSM based dataset on Mapbox more seamless, I was looking into a command line based workflow that could extract OSM data from Overpass and update a Mapbox hosted dataset in one go.
- Use Overpass Turbo to create a query for the data you are interested in extracting. Since i'm interested in bus stops, I first browse the map to Bengaluru, India and then generate a query using the wizard query
highway=bus_stop
- Test your query by confirming that the results on the map are as expected
- Export the query in compact form and save the resulting query to a
query.ql
file[out:json][timeout:25];(node["highway"="bus_stop"](12.946554043930224,77.56158828735352,12.983816808126269,77.62420177459717););out body;>;out skel qt;
- In terminal run
query-overpass query.ql --flat-properties > output.geojson
to download the OSM features into a geojson file - Run
mapbox upload mapbox_username.mapid output.geojson
to create or update a dataset on Mapbox with the geojson.
Known bugs
Cannot use properties with a special character like colon ':'
Affects styling multlingual OSM name tags in Studio, you can replace the colon with underscores (egname:ta
- >name_ta
) in the geojson using this commandsed -i -e "s/name:/name_"/g output.geojson
prior to upload.Studio only recognizes attributes of the first polygon feature in a dataset
For now, run seperate overpass queries to create multiple geojsons for points, ways and areas.Cannot create a tileset with multiple datasets
Uploading individual datasets will each create a new tileset with different mapids. There is currently no way to upload them into a single mapid.
- Visit the Mapbox data page to check the status of your upload
- Once uploaded, open the dataset and add it to your map