1 of 51

自幹向量圖磚

謝晉凡 2019/08/18

捲起袖子前你需要知道的事...

2 of 51

About Me

3 of 51

話說從頭...

4 of 51

So...什麼是向量圖磚?

5 of 51

Who is the big boss?

https://osmcha.mapbox.com/

6 of 51

向量資料 - Vector

Not you ! Raster

Vector !

7 of 51

先來講講圖磚 (Tiles)

  • WGS 84 / Pseudo-Mercator -> 將地球投影成正方形
  • 台灣涵蓋範圍 z8~z14 = 6 * (4^6) = 24,000

z = 1

z = 8

8 of 51

所謂向量圖磚(Vector TIles)

  • 含有向量資料的地圖
    • 包含原始(或加工過)的資料
    • 將大量資料經過切片細分
  • 優點
    • 較好的使用者體驗
    • 在客戶端進行渲染
    • 圖磚檔案容量較小(通常情況下...)
    • 一種格式,能用於多種用途
    • 遵守 MBTiles specs 1.3 (only MVT)

9 of 51

image from: https://blog.woosmap.com

10 of 51

什麼時候適合用向量圖磚?

  • 時間有限、網路流量有限 (Tile)
  • 要呈現的資料很大時 (Tile)
  • 要呈現的資料空間尺度很大時 (Tile)
  • 使用情境需要access原始資料時 (Vector)
  • 使用者會拼命放大畫面時!!(Vector)
  • 前端使用的技術,如:�Open Layer, Leaflet, Mapbox GL, Tangram ES

11 of 51

當然,格式百百種 (下面的看過就好...)

  • MVT (Mapbox Vector Tile)
  • VTM
  • Geojson, Topojson
  • Mapnik Vector Tile
  • ArcJSON, GeoBSON, Arc GeoServices BSON, GeoAMF Arc GeoServices BSON

12 of 51

MVT 搞什麼東東?

  • 使用Google Protobuffer技術壓縮
    • 原則上還是json 檔案
    • 需要decode
  • 官方文件

13 of 51

動手找範例

  • 關鍵字- �Mabox GL, examples, Glossary�
  • mapbox/awesome-vecter-tiles中找個稱手的工具
  • 這邊使用vt2geojson 來介紹...

14 of 51

產製流程大概是這樣...

  • 把原始地理資料,依照自訂規則丟進資料庫 (osm2pgsql, imposm)
  • 針對各個table作前處理 (PostGIS)
  • 依照自訂規則對切片範圍進行query,把成果把打包成MVT�(Tilelive, TIlequeue)

OpenStreetMap

(PBF)

Import

PostGIS

Encode

Vector Tiles�(MVT)

Diff

15 of 51

那麼...哪裡才找得到(原始地理資料)呢?

  • 偉大的德國人! Geofabrik�http://download.geofabrik.de/asia/taiwan.html
  • 政府資料開放平台�https://data.gov.tw/dataset/35430

16 of 51

最常見的工具鏈

OpenStreetMap

(PBF)

Import

PostGIS

Encode

Vector Tiles�(MVT)

17 of 51

最常見的工具鏈

PostGIS

Encode

Vector Tiles�(MVT)

Client

18 of 51

MVT生態 - Mapbox

19 of 51

MVT生態-Tilezen (Nextzen)

20 of 51

And then… OpenMapTiles (MapTiler)

  • 開箱即用的工具鏈
  • 完整細緻的Tile schema
  • 流程 docker 化
  • .org / .com
    • 免費下載過期tile, 付費下載最新版本

21 of 51

Make your tiles with OpenMapTiles

$ git clone https://github.com/openmaptiles/openmaptiles�$ ./quickstart taiwan

  • 182MB (z0 ~z14)
  • with i5-8250U => 100min

22 of 51

全部docker化的工作流程

23 of 51

Not enough ? Serve it !

$ make start-tileserver

24 of 51

Well… a little heavy

25 of 51

Easy to use, with make and docker-compose

$ make help

26 of 51

坑點之一 - 圖磚更新

  • imposm -> 自己讀文件
  • 什麼是sequence number ??�什麼是tile list ??
  • 然後你就等到天荒地老...

27 of 51

取用OSM Diff 來更新

28 of 51

坑點之二 - Wikidata

  • 使用Wikidata的「多語言」特性�完善OSM feature 的name欄位
  • 怎麼做到的? Dump 下來啊!
  • 然後你就等到天荒地老...

29 of 51

$ make serve-taiwan

30 of 51

自幹之外,你也有其它「商業」選擇

31 of 51

Overwhelming?

  • Complex mapping config for OSM data import
  • 273 tables inside PostGIS
  • Still, complex layer config for MVT
  • 10G+ docker images and GBs border/water data
  • I want an easy way to start ...

32 of 51

33 of 51

t-rex! Dinosaur Rules !

  • GDAL backed, suport 56 vector formats
  • Well documented, simple options
  • Default configuation for developer
  • Style in Maputnik, auto data import!
  • All in one small docker image (305MB)

34 of 51

35 of 51

So… What’s next?

  • OSM tags for hiking => https://osmtw.hackpad.tw/--0WDHc4HBSED
  • Custom schema for unpaved paths
  • Reasonable size => <20KB
  • Frontend ? Not my business ^ ^

36 of 51

MVT - the next generation

  • Real 3D features
  • OSGeo support
  • With real-time data (transportation)
  • With visualization (Kepler)

37 of 51

Other Resources

38 of 51

Thanks

39 of 51

Offline Usage - MBTiles

  • Based on the SQLite database
  • Single file for a big set of tiles
  • Work with Vector Tiles:
    • Localhost
    • Index DB + Service worker

40 of 51

講人話 !!

41 of 51

42 of 51

講人話 !!

OpenStreetMap

(PBF)

Import

PostGIS

Encode

Vector Tiles�(MVT)

43 of 51

Where to start? Mapbox Studio

44 of 51

Upload, and style it!

45 of 51

Get outdoor map with contour very quickly

46 of 51

But... be aware of the limits !

47 of 51

But... be aware of the limits !

48 of 51

The most important - OSM Data

49 of 51

  • Workflow and vector tiles are Open Source
  • Compatible with Mapbox products
    • Mapbox streets, Mapbox studio
    • Mapbox GL, Mobile SDKs
  • No vendor lock-in
    • Host tiles yourself
    • offline support (MBTiles)

50 of 51

The roadmap to hell is paved with good intentions...

51 of 51

So what’s the problem?