Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Example script for turning a directory of shps into mbtiles #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions api-scripts/build-tiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# Simple script to convert shapefiles to mbtiles.
#
# Usage:
# * This script assumes your shapefiles are in the directory where the shapefiles are.
# * Run the command as `bash build-tiles.sh`
#
# Dependencies:
# * ogr2ogr (GDAL)
# * tippecanoe (https://github.com/felt/tippecanoe)
# * tile-join (included with tippecanoe)

GEOJSON_DIR=./geojsons
MBTILES_DIR=./mbtiles

mkdir -p $GEOJSON_DIR
mkdir -p $MBTILES_DIR

# TODO gpkg too?
for i in **/*.shp; do
[ -f "$i" ] && echo ${i%.*}

# Use gdal to convert to geojson
mkdir -p $GEOJSON_DIR/$(dirname $i)
ogr2ogr -t_srs EPSG:4326 -f GeoJSON $GEOJSON_DIR/${i%.*}.geojson $i

# Use tippecanoe to convert to mbtiles
mkdir -p $MBTILES_DIR/$(dirname $i)
tippecanoe --force -zg -o $MBTILES_DIR/${i%.*}.mbtiles --drop-densest-as-needed $GEOJSON_DIR/${i%.*}.geojson
done

# Use tile-join to merge mbtiles
#
# --overzoom is significant here since it gets the separate tiles to work on the
# same zooms
tile-join --force --overzoom -o ${PWD##*/}.mbtiles $MBTILES_DIR/**/*.mbtiles

# .mbtiles need a server to open them and serve the tiles within them.
# Alternatively, we could output to a directory of vector tiles like this:
#
# tile-join --force --overzoom -output-to-directory=./vector-tiles $MBTILES_DIR/**/*.mbtiles