Skip to content
Wenyi1995 edited this page Apr 25, 2023 · 44 revisions

HouseSigma custom map project

Map Tools:

Bbox

BC to ON, partial QC
-131,41.7,-73,60

building outline

Daylight Map Distribution 这个地图提供商会每周更新地图建筑,海岸线,道路等信息 下载后的地图需要手动合并

osmium apply-changes planet.osm.pbf buildings.osc.bz2 -o everything.osm.pbf

合并过后用这个命令使修改生效,这个操作很消耗内存,建议在200G以上内存的服务器上操作。

osmium renumber everything.osm.pbf -o ordered-everything.osm.pbf

需要将全球文件导入postgis数据库,可以用 make import ordered-everything 命令 在编译地图的前段操作和以往没有区别,只是在最后将需要的bbox参数写入到bbox文件 然后用make generate-tiles area={bbox file name}编译为mbtiles文件


build map:

font

Test:

ovh06:~/hsmaptiles# git pull

ovh06:~/hsmaptiles# ./quickstart.sh Toronto

ovh06:~/hsmaptiles# make start-tileserver

build map (quick)

./quickstart.sh ontario

build map (Production)

make help

==============================================================================
 OpenMapTiles  https://github.com/openmaptiles/openmaptiles
Hints for testing areas
  make list-geofabrik                  # list actual geofabrik OSM extracts for download -> <<your-area>>
  ./quickstart.sh <<your-area>>        # example:  ./quickstart.sh madagascar

Hints for designers:
  make start-maputnik                  # start Maputnik Editor + dynamic tile server [ see http://localhost:8088 ]
  make start-postserve                 # start dynamic tile server                   [ see http://localhost:8090 ]
  make start-tileserver                # start maptiler/tileserver-gl                [ see http://localhost:8080 ]

Hints for developers:
  make                                 # build source code
  make list-geofabrik                  # list actual geofabrik OSM extracts for download
  make list-bbbike                     # list actual BBBike OSM extracts for download
  make download area=albania           # download OSM data from any source       and create config file
  make download-geofabrik area=albania # download OSM data from geofabrik.de     and create config file
  make download-osmfr area=asia/qatar  # download OSM data from openstreetmap.fr and create config file
  make download-bbbike area=Amsterdam  # download OSM data from bbbike.org       and create config file
  make generate-bbox-file              # compute bounding box of a data file and store it in a file
  make psql                            # start PostgreSQL console
  make psql-list-tables                # list all PostgreSQL tables
  make vacuum-db                       # PostgreSQL: VACUUM ANALYZE
  make analyze-db                      # PostgreSQL: ANALYZE
  make generate-qa                     # statistics for a given layer's field
  make generate-devdoc                 # generate devdoc including graphs for all layers [./layers/...]
  make bash                            # start openmaptiles-tools /bin/bash terminal
  make destroy-db                      # remove docker containers and PostgreSQL data volume
  make start-db                        # start PostgreSQL, creating it if it doesn't exist
  make start-db-preloaded              # start PostgreSQL, creating data-prepopulated one if it doesn't exist
  make stop-db                         # stop PostgreSQL database without destroying the data
  make clean-unnecessary-docker        # clean unnecessary docker image(s) and container(s)
  make refresh-docker-images           # refresh openmaptiles docker images from Docker HUB
  make remove-docker-images            # remove openmaptiles docker images
  make list-views                      # list PostgreSQL public schema views
  make list-tables                     # list PostgreSQL public schema tables
  cat  .env                            # list PG database and MIN_ZOOM and MAX_ZOOM information
  cat  quickstart.log                  # transcript of the last ./quickstart.sh run
  make help                            # help about available commands
==============================================================================

更新docker image

make refresh-docker-images

调整postgres参数

/var/lib/docker/volumes/hsmaptilesbuild_pgdata/_data/postgresql.conf

另一个办法: https://gist.github.com/smellman/559f74158447c60ebc88c8bc12ebb505

docker-compose 版本当前是 v2.6.1

listen_addresses = '*'
max_connections = 200                   # (change requires restart)
shared_buffers = 24GB           # min 128kB

work_mem = 31457kB                      # min 64kB
maintenance_work_mem = 2GB              # min 1MB
dynamic_shared_memory_type = posix      # the default is the first option

effective_io_concurrency = 2    # 1-1000; 0 disables prefetching
max_worker_processes = 8                # (change requires restart)
max_parallel_workers_per_gather = 4     # taken from max_worker_processes

wal_buffers = 16MB                      # min 32kB, -1 sets based on shared_buffers

max_wal_size = 4GB
min_wal_size = 1GB
checkpoint_completion_target = 0.9      # checkpoint target duration, 0.0 - 1.0
random_page_cost = 4            # same scale as above
effective_cache_size = 72GB

default_statistics_target = 100 # range 1-10000
log_timezone = 'Etc/UTC'

datestyle = 'iso, mdy'
#intervalstyle = 'postgres'
timezone = 'Etc/UTC'

lc_messages = 'en_US.utf8'                      # locale for system error message
lc_monetary = 'en_US.utf8'                      # locale for monetary formatting
lc_numeric = 'en_US.utf8'                       # locale for number formatting
lc_time = 'en_US.utf8'                          # locale for time formatting

default_text_search_config = 'pg_catalog.english'

启动停止postgres sql docker。

make start-db
make stop-db

导入数据。

make import-data
make download area=north-america

# 修改 .env BBOX
BBOX=-134.42,40.2,-51.11,57.98
Delete the ./data/<area>.bbox file

# area 就是osm.pbf下载文件的名字。
make import-osm area=north-america
make import-borders area=north-america
make import-wikidata area=north-america

Each time changed SQL for layer

make clean
make
make import-sql
make analyze-db
make test-perf-null

# one line
make clean && make && make import-sql 
make analyze-db && make test-perf-null

generate vector tile

make generate-bbox-file  area=north-america # compute data bbox -- not needed for the whole planet
make generate-tiles   area=north-america    # generate tiles

after build, move mbtiles to server dir

  • cp data/tiles.mbtiles server/Toronto.mbtiles

tileserver-gl only

docker run --rm --user=0:0 -it --name tileserver-gl -v $(pwd)/server:/data -p 8080:8080 maptiler/tileserver-gl --port 8080 --verbose

# run in background
docker run -d --rm -it -v $(pwd)/server:/data -p 8080:80 maptiler/tileserver-gl --config ./config.json

config.json doc https://tileserver.readthedocs.io/en/latest/config.html?highlight=config

deploy map:

添加地图数据源, 配置 config.json

"data": {
    "basemap_bc_on_qc_ny_mi": {
      "mbtiles": "BC_ON_QC_NY_MI.mbtiles"
    }
    ...
}

修改地图样式 style.json,修改 openmaptiles 数据源为新添加的数据源 id

"sources": {
  "openmaptiles": {
    "type": "vector",
    "url": "mbtiles://{basemap_bc_on_qc_ny_mi}"
  },
  ...
}

保存后重启即可

cd ~/mbtiles
# 清空当前正在运行的所有 docker 服务
docker stop $(docker ps -aq) && docker rm $(docker ps -aq)
# 重新启动地图服务
docker run -d --restart=always -it -v $(pwd):/data -p 8080:80 maptiler/tileserver-gl --config ./config.json

如何添加地块 mbtiles 到当前地图

配置地块数据源

"data": {
    "properties": {
      "mbtiles": "properties-toronto.mbtiles"
    }
}

style.json 中添加地块 source

"sources": {
  ...
  "properties": {
    "type": "vector",
    "url": "mbtiles://{properties}"
  }
},

使用 mbtiles 查看工具,比如 sqlitebrowser, 查看当前地块的 layerId

使用 Maputnik 编辑 style.json, 添加地块的layer, layerId 为 PROPERTY_BOUNDARIES_WGS84

也可以直接把下面的json 添加到 style.json 的 layers 数组中

{
  "id": "properties_range",
  "type": "line",
  "source": "properties",
  "source-layer": "PROPERTY_BOUNDARIES_WGS84",
  "minzoom": 18,
  "paint": {
    "line-color": "rgba(111, 111, 111, 1)"
  }
}

最后将 style.json 导出,并上传到服务器,重启 docker 容器即可


bc省地块 gdb 导出为 geojson

ogr2ogr -t_srs 'EPSG:4326' -f GeoJSON -where 'PARCEL_STATUS="Active"' bc.geojson bc.gdb -dialect OpenFileGDB

参数:

  • bc.geojson 为输出文件名
  • bc.gdb是输入文件名
  • -t_srs 参数指定坐标系。

shp 文件转换 geojson

ogr2ogr -f GeoJSON -s_srs input.prj -t_srs EPSG:4326 output.geojson input.shp

多个 geojson 文件编译为mbtiles文件

tippecanoe -zg -o bc_on.mbtiles -l PROPERTY_BOUNDARIES_WGS84 --coalesce-densest-as-needed --extend-zooms-if-still-dropping bc.geojson on.geojson

参数:

  • bc_on.mbtiles 是输出文件名
  • bc.geojsonon.geojson是输入文件名,如果有多个geojson文件则继续往后添加
  • -zg参数是指自动获取编译的zoom级别,如果不想太大的级别可以指定一个。比如:z7就只编译到 zoom 7

两个额外参数

  • --coalesce-densest-as-needed 如果图块在低或中等缩放级别下太大,则将尽可能多的特征合并在一起,以允许创建具有仍可区分的特征的图块
  • --extend-zooms-if-still-dropping 如果即使是高缩放级别的图块也太大,请继续添加缩放级别,直到达到可以代表所有功能的缩放级别