Skip to content

Commit

Permalink
Adds the simplification mode documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ibesora committed Oct 28, 2018
1 parent 226460d commit 74dd73c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Vector Tile optimizer

[![Build Status Linux](https://travis-ci.org/ibesora/vt-optimizer.svg?branch=master)](https://travis-ci.org/ibesora/vt-optimizer)
> A small NodeJS cli tool to inspect and optimize [Mapbox Vector Tiles](https://www.mapbox.com/vector-tiles/) files
[![Build status](https://ci.appveyor.com/api/projects/status/7c6haos5thbxrnu4/branch/master?svg=true)](https://ci.appveyor.com/project/ibesora/vt-optimizer/branch/master)
![Dependency Status](https://david-dm.org/ibesora/vt-optimizer.svg)
![License](https://img.shields.io/badge/license-MIT-blue.svg)
> A small NodeJS cli tool to inspect and optimize [Mapbox MBTiles files](https://github.com/mapbox/mbtiles-spec) used to encode [Mapbox Vector Tiles](https://www.mapbox.com/vector-tiles/).
<img src="media/example.gif">

Expand Down Expand Up @@ -49,4 +52,9 @@ It reads both the Vector Tile and style and removes all the layers and features
**Note:** To use the optimization tool it's better to run the `--max-old-space-size` NodeJS argument to increase NodeJS process heap space as the entire Vector Tile is loaded and decompressed when working.
```
node --max-old-space-size=16386 index.js -m files/input.mbtiles -s files/style.json -o files/output.mbtiles
```
```
### Vector Tile layer simplification
When running the tool with the *-x X -y Y -z Z -l layerName -t tolerance* arguments, the simplification mode will be started. This mode is used for simplifying a layer on a given tile. **Note:** The tolerance value is in degrees (1º is aproximately 110 meters) and tells the algorithm that two points with a distance lower than the tolerance value should be merged.

When the process is finished, the results of the simplification are shown.
<img src="media/simplify.PNG">
Binary file added media/simplify.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/core/VTProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,11 @@ class VTProcessor {

}

ctx.startingCoordinatesNum = layerToSimplify.features.reduce((accum, elem) => accum + elem.geometry.coordinates.length, 0);
ctx.startingCoordinatesNum = layerToSimplify.features.reduce((accum, feature) => accum + feature.geometry.coordinates.reduce((accum, ring) => (ring.length ? accum + ring.length : feature.geometry.coordinates.length / 2), 0), 0);
Simplifier.simplifyGeoJSON(layerToSimplify, tolerance)
.then(data => {

ctx.simplifiedCoordinatesNum = data.features.reduce((accum, elem) => accum + elem.geometry.coordinates.length, 0);
ctx.simplifiedCoordinatesNum = data.features.reduce((accum, feature) => accum + feature.geometry.coordinates.reduce((accum, ring) => (ring.length ? accum + ring.length : feature.geometry.coordinates.length / 2), 0), 0);
ctx.geojsons[layerName] = data;
resolve();

Expand Down

0 comments on commit 74dd73c

Please sign in to comment.