-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f24b546
commit f616d94
Showing
8 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Generate tiles | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: "0 0 * * *" # every day at midnight | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: set up Homebrew | ||
id: set-up-homebrew | ||
uses: Homebrew/actions/setup-homebrew@master | ||
|
||
- name: install tippecanoe | ||
run: brew install tippecanoe | ||
|
||
- name: run python download script | ||
run: python3 download.py | ||
|
||
- name: run the generate shell file | ||
run: ./generate.sh | ||
|
||
- name: check for changes | ||
run: git status | ||
|
||
- name: commit changed files | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git add . | ||
git diff-index --quiet HEAD || git commit -m "Auto regeneration of tiles" | ||
- name: fetch from main | ||
run: git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* | ||
|
||
- name: push code to main | ||
run: git push origin HEAD:main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tiles.mobilelibraries.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,26 @@ | ||
# mobilelibraries-tiles | ||
# Mobile libraries tiles | ||
|
||
Vector tiles for the mobile libraries project | ||
|
||
## How it works | ||
|
||
The [Mobile libraries API](https://github.com/LibrariesHacked/mobilelibraries-api) exposes endpoints to retrieve mobile library stops and trips as GeoJSON. This repository contains scripts that will extract these GeoJSON files on a nightly basis and convert them into static vector tiles. | ||
|
||
Those vector tiles are then available as [Mapbox Vector Tiles](https://github.com/mapbox/vector-tile-spec) for use in web maps. There will be two layers embedded into each tile: `stops` and `trips`. The `stops` layer contains the location of each stop, and the `trips` layer contains the route taken by the mobile library between different stops. | ||
|
||
The process is as follows: | ||
|
||
1. Download the latest GeoJSON from the Mobile libraries API (see `download.py`). | ||
2. Use tippecanoe to convert the GeoJSON to a directory of static tiles within the `\libraries` directory (see `generate.sh`) | ||
|
||
This repository is published as a GitHub pages site, which makes the tiles available in high performance web hosting. | ||
|
||
## How to use | ||
|
||
These tiles are made available via GitHub pages and a custom domain. They are available at `https://tiles.mobilelibraries.org/tiles/{z}/{x}/{y}.mvt` | ||
|
||
## Licence | ||
|
||
The tiles are from data compiled by the public and by public library services. They are licensed under the [Open Government Licence](http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/). | ||
|
||
Code in this repository is available under the [MIT Licence](LICENSE). |
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" Download the geojson files from the Mobile libraries API and save to data directory. """ | ||
|
||
import json | ||
import os | ||
import requests | ||
|
||
GEOJSON_STOPS_URL = 'https://api.mobilelibraries.org/api/stops?limit=20000' | ||
GEOJSON_TRIPS_URL = 'https://api.mobilelibraries.org/api/trips' | ||
|
||
|
||
def download_geojson(url): | ||
"""Download the geojson file and return the json data.""" | ||
|
||
headers = {"Accept": "application/geo+json"} | ||
response = requests.get(url, headers=headers, timeout=10) | ||
return response.json() | ||
|
||
|
||
def save_geojson(data, file_name): | ||
"""Save the geojson data to the data directory.""" | ||
|
||
if not os.path.exists('data'): | ||
os.makedirs('data') | ||
|
||
with open(f'data/{file_name}', 'w', encoding='utf-8') as f: | ||
json.dump(data, f) | ||
|
||
|
||
stops_geojson = download_geojson(GEOJSON_STOPS_URL) | ||
save_geojson(stops_geojson, 'stops.geojson') | ||
|
||
trips_geojson = download_geojson(GEOJSON_TRIPS_URL) | ||
save_geojson(trips_geojson, 'trips.geojson') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rm -rf tiles | ||
mkdir tiles | ||
tippecanoe -r1 --no-tile-compression --drop-densest-as-needed --no-tile-size-limit --output-to-directory data/stops.geojson data/trips.geojson --force | ||
find . -name '*.pbf' -exec sh -c 'mv "$0" "${0%.pbf}.mvt"' {} \; |