Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save answerquest/72e26f11d3da1069cbb02032633a71df to your computer and use it in GitHub Desktop.
Save answerquest/72e26f11d3da1069cbb02032633a71df to your computer and use it in GitHub Desktop.
hydroSHEDS.org data vector tile layer publishing

hydroSHEDS.org data vector tile layer publishing

  • linux/shell commands used
  • to process data downloaded from https://www.hydrosheds.org/
  • clipping it to a rectangle around India to reduce to India data
  • converting to .geojsonl
  • creating .mbtiles using tippecanoe
  • publishing on an TileServerGL instance

clip to India rectangle and convert to .geojsonl using ogr2ogr

ogr2ogr -f "GeoJSONSeq" /vsistdout/ GloRiC_v10_shapefile/GloRiC_v10.shp -clipsrc 67.104 5.195 98.357 37.952 >> GloRiC_v10_India.geojsonl
ogr2ogr -f "GeoJSONSeq" /vsistdout/ HydroLAKES_polys_v10_shp/HydroLAKES_polys_v10.shp -clipsrc 67.104 5.195 98.357 37.952 >> HydroLAKES_polys_v10_India.geojsonl
ogr2ogr -f "GeoJSONSeq" /vsistdout/ HydroRIVERS_v10_as_shp/HydroRIVERS_v10_as.shp -clipsrc 67.104 5.195 98.357 37.952 >> HydroRIVERS_v10_India.geojsonl
ogr2ogr -f "GeoJSONSeq" /vsistdout/ HydroLAKES_points_v10_shp/HydroLAKES_points_v10.shp -clipsrc 67.104 5.195 98.357 37.952 >> HydroLAKES_points_v10_India.geojsonl
ogr2ogr -f "GeoJSONSeq" /vsistdout/ HydroBASINS/hybas_as_lev08_v1c.shp -clipsrc 67.104 5.195 98.357 37.952 >> hybas_as_lev08_v1c.geojsonl
ogr2ogr -f "GeoJSONSeq" /vsistdout/ HydroBASINS/hybas_as_lev12_v1c.shp -clipsrc 67.104 5.195 98.357 37.952 >> hybas_as_lev12_v1c.geojsonl

tippecanoe commands to create .mbtiles

nohup tippecanoe -o ~/building_footprints/mbtiles2/GloRiC_v10_India_z16.mbtiles -f \
-n "GloRiC_v10" -l "GloRiC_v10" \
-N "https://www.hydrosheds.org/products/gloric#downloads GloRiC_v10_shapefile.zip converted to .geojsonl and clipped to India region using ogr2ogr then converted to .mbtiles using tippecanoe by https://github.com/answerquest, all credits to original data authors" \
-z16 --drop-densest-as-needed --drop-smallest-as-needed --extend-zooms-if-still-dropping --read-parallel \
GloRiC_v10_India.geojsonl &

nohup tippecanoe -o ~/building_footprints/mbtiles2/HydroRIVERS_v10_India.mbtiles -f \
-n "HydroRIVERS_v10_India" -l "HydroRIVERS_v10_India" \
-N "https://www.hydrosheds.org/products/hydrorivers HydroRIVERS_v10_as_shp.zip converted to .geojsonl and clipped to India region using ogr2ogr then converted to .mbtiles using tippecanoe by https://github.com/answerquest, all credits to original data authors" \
-z16 --drop-densest-as-needed --drop-smallest-as-needed --extend-zooms-if-still-dropping --read-parallel \
HydroRIVERS_v10_India.geojsonl &

nohup tippecanoe -o ~/building_footprints/mbtiles2/HydroLAKES_polys_v10_India.mbtiles -f \
-n "HydroLAKES_polys_v10_India" -l "HydroLAKES_polys_v10_India" \
-N "https://www.hydrosheds.org/products/hydrolakes HydroLAKES_polys_v10_shp.zip converted to .geojsonl and clipped to India region using ogr2ogr then converted to .mbtiles using tippecanoe by https://github.com/answerquest, all credits to original data authors" \
-z16 --drop-densest-as-needed --drop-smallest-as-needed --extend-zooms-if-still-dropping --read-parallel \
HydroLAKES_polys_v10_India.geojsonl &

nohup tippecanoe -o ~/building_footprints/mbtiles2/HydroLAKES_points_v10_India.mbtiles -f \
-n "HydroLAKES_points_v10_India" -l "HydroLAKES_points_v10_India" \
-N "https://www.hydrosheds.org/products/hydrolakes HydroLAKES_points_v10_shp.zip converted to .geojsonl and clipped to India region using ogr2ogr then converted to .mbtiles using tippecanoe by https://github.com/answerquest, all credits to original data authors" \
-z16 --drop-densest-as-needed --drop-smallest-as-needed --extend-zooms-if-still-dropping --read-parallel \
HydroLAKES_points_v10_India.geojsonl &

nohup tippecanoe -o ~/building_footprints/mbtiles2/hybas_as_lev08_v1c.mbtiles -f \
-n "hybas_as_lev08_v1c" -l "hybas_as_lev08_v1c" \
-N "https://www.hydrosheds.org/products/hydrobasins Asia download converted to .mbtiles using tippecanoe by https://github.com/answerquest, all credits to original data authors" \
-z16 --coalesce-densest-as-needed --drop-densest-as-needed --extend-zooms-if-still-dropping --read-parallel \
"hybas_as_lev08_v1c.geojsonl" &

nohup tippecanoe -o ~/building_footprints/mbtiles2/hybas_as_lev12_v1c.mbtiles -f \
-n "hybas_as_lev12_v1c" -l "hybas_as_lev12_v1c" \
-N "https://www.hydrosheds.org/products/hydrobasins Asia download converted to .mbtiles using tippecanoe by https://github.com/answerquest, all credits to original data authors" \
-z16 --coalesce-densest-as-needed --drop-densest-as-needed --extend-zooms-if-still-dropping --read-parallel \
"hybas_as_lev12_v1c.geojsonl" &

note: these commands were run on a linux (ubuntu) VPS webserver hosted at SSDNodes thru SSH connection. The "nohup" prefix and "&" suffix makes the command run in background and it doesn't terminate if the user gets disconnected from the server.

Running TileServerGL

  • note: showing a reduced part of a larger config

config.json:

"options": {
    "paths": {
      "root": "",
      "fonts": "",
      "sprites": "",
      "styles": "",
      "mbtiles": "/data"
    }
  },
  "data": {
    "hydrosheds.org-GloRiC_v10_India": {
      "mbtiles": "GloRiC_v10_India_z16.mbtiles"
    },
    "hydrosheds.org-HydroLAKES_polys_v10_India": {
      "mbtiles": "HydroLAKES_polys_v10_India.mbtiles"
    },
    "hydrosheds.org-HydroLAKES_points_v10_India": {
      "mbtiles": "HydroLAKES_points_v10_India.mbtiles"
    },
    "hydrosheds.org-HydroRIVERS_v10_India": {
      "mbtiles": "HydroRIVERS_v10_India.mbtiles"
    },
    "hydrosheds.org-HydroBASINS_lev08_India": {
      "mbtiles": "hybas_as_lev08_v1c.mbtiles"
    },
    "hydrosheds.org-HydroBASINS_lev12_India": {
      "mbtiles": "hybas_as_lev12_v1c.mbtiles"
    }
  }
}
  • Place config.json and the .mbtiles files in the same folder, and run this docker command:
docker run --name tileserver1 -d -v "$(pwd)":/data -p 7100:8080 -p 7101:80 maptiler/tileserver-gl -c config.json -b 0.0.0.0 -u "https://server.nikhilvj.co.in/tileserver/"
  • Omit the last "-u " part if you're doing this on a local system only

  • On local system, open http://localhost:7100 in browser.

  • If doing on a web-facing server, then in apache conf file, add proxy & reverse proxy linking port 7100 to the site path.

  • My setting:

    ProxyPass /tileserver/ http://127.0.0.1:7100/
    ProxyPassReverse /tileserver/ http://127.0.0.1:7100/
  • Won't go into nitty gritties of setting up apache server here, pls look up online; DigitalOcean has good guides
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment