Skip to content

Instantly share code, notes, and snippets.

@smellman
Last active May 19, 2023 16:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smellman/f6c397014186bb5373c96b5aed54e1de to your computer and use it in GitHub Desktop.
Save smellman/f6c397014186bb5373c96b5aed54e1de to your computer and use it in GitHub Desktop.
SRTM to tile

SRTM Contour to vector tile

Download SRTM Contour from OpenDEM Project

#!/bin/bash

urls=urls.txt
base_url=http://opendemdata.info/data/srtm_contour
for y in `seq -w 0 85`;
do
  for x in `seq -w 0 180`;
  do
    echo "$base_url/N${y}W${x}.zip" >> $urls
    echo "$base_url/S${y}W${x}.zip" >> $urls
    echo "$base_url/N${y}E${x}.zip" >> $urls
    echo "$base_url/S${y}E${x}.zip" >> $urls
  done
done
sh make_dl_list.sh
mkdir files
cd files
aria2c -i ../urls.txt

Create working directory and move zip files

mkdir zips
cd zips
mv ../download/files/*.zip .

Unzip all

parallel unzip ::: *zip

Merge all files

ogrmerge.py -single -f GPKG -o merged.gpkg */*.shp

Convert vector tile via tippecanoe (felt fork)

ogr2ogr -f GeoJSONSeq /vsistdout merged.gpkg | tippecanoe -Z9 -z11 -pf -M 2000000 -P -o contour.mbtiles -l contour -n "Contour line" -A "<a href=\"https://www.opendem.info/index.html\" target=\"_blank\">&copy; OpenDEM</a>. License under ODbL."

SRTM to DEM raster tile

Download SRTM v3 from viewfinderpanoramas.org

wget -r -np -l 1 -A zip "http://viewfinderpanoramas.org/Coverage%20map%20viewfinderpanoramas_org3.htm"

create working direcotry and move all zip files

mkdir zips
cd zips
mv ../viewfinderpanoramas.org/dem3/*.zip .
mv ../viewfinderpanoramas.org/A21.zip .
mv ../viewfinderpanoramas.org/ANTDEM3/*.zip .

Unzip all

for i in `ls *.zip`; do unzip $i; done

Create tiff file

gdalbuildvrt -a_srs EPSG:4326 -hidenodata all.vrt */*.hgt
gdal_translate -co compress=lzw -co BIGTIFF=YES -of GTiff all.vrt all.tiff
gdal_calc.py --co="COMPRESS=LZW" --co="BIGTIFF=YES" --type=Float32 -A all.tiff --outfile=all_calc.tiff --calc="A*(A>0)" --NoDataValue=0

Setup venv and install rio-rgbify

sudo apt-get install python3-venv libpython3-dev libgdal-dev
python3 -m venv venv
source venv/bin/activate
pip install gdal
git clone https://github.com/mapbox/rio-rgbify.git
cd rio-rgbify
pip install -e '.[test]'

Run rio rgbify

rio rgbify -b -10000 -i 0.1 --format png --max-z 11 --min-z 5 all_calc.tiff dem.mbtiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment