Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Process USFS motor vehicle use data into vector tiles
#!/bin/bash
set -e -u
wget https://data.fs.usda.gov/geodata/edw/edw_resources/shp/S_USA.Road_MVUM.zip
wget https://data.fs.usda.gov/geodata/edw/edw_resources/shp/S_USA.Trail_MVUM.zip
unzip S_USA.Road_MVUM.zip
unzip S_USA.Trail_MVUM.zip
TRAILS_MBTILES=`pwd`/trails.mbtiles
ROADS_MBTILES=`pwd`/roads.mbtile
echo "Processing roads"
ogr2ogr -t_srs epsg:4326 -f GeoJSON S_USA.Road_MVUM.geojson S_USA.Road_MVUM.shp
tippecanoe -Z 10 -l roads -o $ROADS_MBTILES S_USA.Road_MVUM.geojson
echo "Processing trails"
ogr2ogr -t_srs epsg:4326 -f GeoJSON S_USA.Trail_MVUM.geojson S_USA.Trail_MVUM.shp
tippecanoe -Z 10 -l trails -o $TRAILS_MBTILES S_USA.Trail_MVUM.geojson
WORK_DIR=`pwd`
TILE_LIST=`pwd`/combined.tiles
COMBINED_MBTILES=`pwd`/combined.mbtiles
echo "generating tile list"
QUERY="SELECT zoom_level, tile_column, (1 << zoom_level) - 1 - tile_row from tiles"
sqlite3 $TRAILS_MBTILES "$QUERY" | sed -e 's/|/\//g' > $WORK_DIR/trails.tiles
sqlite3 $ROADS_MBTILES "$QUERY" | sed -e 's/|/\//g' > $WORK_DIR/roads.tiles
cat $WORK_DIR/trails.tiles $WORK_DIR/roads.tiles | sort | uniq > $TILE_LIST
echo "Merging tiles"
./tilelive/bin/tilelive-copy \
--concurrency=1 \
--scheme=list \
--list=$TILE_LIST \
"merge:\?source=mbtiles://$TRAILS_MBTILES&source=mbtiles://$ROADS_MBTILES" \
"mbtiles://$COMBINED_MBTILES"
#hack to make tilelive-copy copy over the metadata, because it doesnt do it in list mode
./tilelive/bin/tilelive-copy \
--concurrency=1 \
--scheme=pyramid \
--minzoom=0 \
--maxzoom=1 \
"merge:\?source=mbtiles://$TRAILS_MBTILES&source=mbtiles://$ROADS_MBTILES" \
"mbtiles://$COMBINED_MBTILES"
rm $TILE_LIST $TRAILS_MBTILES $ROADS_MBTILES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment