one-off vector tiles Let’s set up some bespoke data layers! Motivation We might do this to build a visualization to debug some data in OSM, for which a general-purpose vector map tiler would not meet our needs. For example, here’s a statewide map including all administrative and census boundaries in Pennsylvania. On a typical map we wouldn’t see the admin boundaries until zoom 11, 12, perhaps 14. The census boundaries probably wouldn’t be rendered at all. So we need to extract the data we’re interested, perhaps rendering it atop a general-purpose basemap. Shown here at approximately zoom level 8. Reasons this could be useful: - Specialized views of any vector data, OSM or other - This could similarly useful for any feature set that you need a dense, small scale map of. And some numbers for the curious: - Raw json OSM data from overpass - 38M (5M gzipped) - Geojson output - 42M (5M gzipped) - Mbtiles - 110M (87M gzipped) - Unpacked tiles - 199M (47,561 files) We can open the geojson directly in e.g. Kepler, but it’s still a large download, and very slow. Simplifying for low zoom levels is important. (The mbtiles contains zoom levels 0 thru 14) Let’s get started! Our data pipeline will look roughly like this: 1. Extract with overpass 2. Convert to mbtiles 3. Develop a stylesheet 4. Host it somewhere 1. Extract with overpass [out:json]; area[wikidata=Q1400]->.a; // Pennsylvania ( rel(area.a)[type=boundary][boundary=administrative]; rel(area.a)[type=boundary][boundary=census]; ); out;>;out skel qt; We’ll repeat this for each state we need. > Idea: We need to keep the layers separate so that we can style them differently, but perhaps we could add a property to each feature indicating what state it’s from. curl 'https://overpass-api.de/api/interpreter' --get --data-urlencode 'data=(insert query)' > pa.json 2. Convert to mbtiles Tippecanoe can only consume geojson, so first convert the OSM data: npm install osmtogeojson pa.geojson osmtogeojson tippecanoe -o pa.mbtiles pa.geojson Not passing any arguments to control it. It defaults to zoom level 14, which has a resolution of 0.5m. > Idea: Depending on the use case could easily pull back a few zoom levels and save a huge amount of time and space. > Sizes from -z10 thru -z14 > -z10 - 3.7M > -z11 - 6.2M > -z12 - 14M > z13 - 36M > z14 - 110M > Even at z10, we can zoom in pretty far before we encounter glaring visual glitches. This is fantastic. > Idea: Deploy to a platform such as Cloud Run, it has great cold boot times for tiny images. 3. Develop a stylesheet We need to serve the tiles to do this. go get github.com/consbio/mbtileserver mkdir tilesets && mv pa.mbtiles tilesets/ mbtileserver There are plenty of ways to serve the tilesets. We can also run tippecanoe with `-e` instead of `-o`, to output loose files. This takes up more space on disk but can be useful if you want to upload to a storage bucket. asdf Exercises Mapbox