Use the Tippecanoe tool to process large amounts of vector data slices

Tippecanoe is an open source slicing tool of Mapbox. The project address is: https://github.com/mapbox/tippecanoe . For Mapbox's conventional slicing method tilelive-copy, see another blog . Tippecanoe mainly has great advantages when dealing with large data volumes, has high efficiency, and has many parameters to control. Tippecanoe can only process GeoJSON, so you need to convert the vector data to GeoJSON before slicing. It is recommended to use the ogr2ogr tool to convert. The format after slicing is mbtiles, which can be imported into databases such as mongodb by itself.

1. Configure GDAL in Linux system

The ogr2ogr tool is in GDAL. To install GDAL in Linux, you need to install PROJ.4, GEOS, and GDAL respectively. This experiment uses proj- 4.8.0 , geos-3.3.8 , and gdal-1.10.0 . Click to directly enter the download address. Before installation, please make sure that gcc, g++, make have been installed in the system. If not, please install it by yourself. 
Unzip the downloaded compressed files separately, and run in sequence in the folder:

$ ./configure
$ make 
$ make install

After the installation is complete, the default path of the command is /usr/local/bin, the library file is in /usr/local/lib, and the source code is in /usr/local/include. Run gdalinfo at this point:

$ gdalinfo

write picture description here

The above results show that the installation is successful. 
Note:  If there is a prompt that the shared library cannot be found, follow the steps below: 
1. Modify the /etc/ld.so.conf file and add the shared library path "/usr/local/lib" into it. 
2. Run ldconfig the command to make it take effect. Whenever a new shared library is added, you need to run the ldconfig command.

2. Convert the data to GeoJSON

This experiment is to convert from the postgis database, the conversion command is:

$ ogr2ogr -f "GeoJSON" ./filename.json PG:"host=localhost dbname=timeline user=ms password=ms" -sql "select * from tablename" -t_srs="epsg:4326"

For other commands, please refer to: https://morphocode.com/using-ogr2ogr-convert-data-formats-geojson-postgis-esri-geodatabase-shapefiles/

In order to avoid turning one by one, it can be written as a shell for batch processing:

#!bin/sh
for layer in "layer1" "layer2" "layer3" "layer4"
do
  echo "$layer convert start"
  ogr2ogr -f "GeoJSON" ./$layer.json PG:"host=localhost dbname=timeline user=ms password=ms" -sql "select * from $layer" -t_srs="epsg:4326"
  echo "$layer convert successful"
done

3. Install tippecanoe

Download the source code from github: https://github.com/mapbox/tippecanoe/releases 
Enter the commands in turn to compile and install:

$ make
$ make install

4. Slicing

$ tippecanoe -z 14 -Z 12 -ps -Bg -o river_live.mbtiles *.json

-Bg is automatic suction to avoid too many elements in a single tile 
*.json is all json files in the current folder, a layer will be automatically created for each file, the layer name is the file name

5. Import mbtiles into mongodb

The vector tiles of this project need to be managed in mongodb, and mbtiles need to be imported into mongodb. At this time, tilelive-copy can be used to import, which is very fast.

$ tilelive-copy mbtiles:///path/to/mbtiles/file.mbtiles "foxgis+mongodb://localhost/zootop?tileset_id=****&owner=****" --timeout=200000000

Finally, if after loading the vector tiles, the rendering shows a hollow triangle, such as the following effect:

write picture description here

This is because tippecanoe automatically sucks and simplifies some line coordinates. You can add the -ps option when slicing to prohibit simplifying line features.

$ tippecanoe -z 14 -Z 12 -ps -Bg -o river_live.mbtiles *.json

The correct rendering result is as follows: 
write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325556821&siteId=291194637