package
Build up a pyramid of vector tiles by aggregating quantitative data into grids at lower zooms.
npm install vt-gridGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Build up a pyramid of Mapbox vector tiles by aggregating quantitative data into grids at lower zooms.
Say you have a dataset of polygons that have some kind of density data (population, vegetation, ...), and you want to build an interactive map with it. Vector tiles are great for this--especially with mapbox-gl steadily maturing.
But if your data is at a fine resolution and you don't want to be limited to very high zoom levels, you're stuck using standard simplification techniques. (Or, much better, the rather badass and blazingly fast simplification and point dropping techniques offered by tippecanoe). For many cases, this works great, but it's not ideal here: for instance, in simplification many small, high-density polygons get dropped, even though these are often important features.
This tool is an alternative to simplification: using a grid whose resolution varies with zoom level, aggregate the quantitative features of interest, so that you can visualize the spatial distribution of your data at any scale.
Install tippecanoe, and then:
npm install -g vt-gridTo start, you'll need an mbtiles file containing the original feature data at
some (high) zoom level. If you've got the data in, say, a shapefile or
PostGIS, you can use Mapbox Studio to create a source and then export to
MBTiles -- just set the min and max zoom to something high enough.
Let's say you've got the data in data.mbtiles, at zoom 12 in a layer called
'foo', and each polygon in this layer has a field called density. Then, you
can build the grid pyramid above this base layer with:
vt-grid input.mbtiles -o output.mbtiles --basezoom 12 --minzoom 1 --gridsize 16 \
--aggregations 'foo:areaWeightedMean(density)'Starting at zoom 11 and going down to zoom 1, this will build a 16x16 grid in
each tile, aggregating the data from the zoom level above. The aggregations
are defined by the --aggregations parameters. Each one is of the form:
layer:aggregationFunction(field), where aggregationFunction can
be any of the built-in aggregations available in
geojson-polygon-aggregate.
So, in this case, we'll end up with a grid where each box has a density
property, which is the (correctly weighted) mean of the densities of the
polygons from the previous (higher) zoom level that fall within that box.
With other aggregations, other stats. For instance, we could have done:
# first use count() to find out the number of polygons from the original
# dataset being aggregated into each grid box at z11
vt-grid input.mbtiles output.mbtiles --basezoom 12 --minzoom 11 --gridsize 16 \
--aggregations 'foo:areaWeightedMean(density)' 'foo:count(numzones)'
# now, for z10 and below, sum the counts
vt-grid input.mbtiles output.mbtiles --basezoom 12 --minzoom 11 --gridsize 16 \
--aggregations 'foo:areaWeightedMean(density)' 'foo:sum(numzones)'You can have a little more flexibility with aggregations (and post-aggregation functions) by using vt-grid programmatically:
var path = require('path')
var vtGrid = require('vt-grid')
var reducers = require('geojson-polygon-aggregate/reducers')
if (require.main === module) {
vtGrid('/path/to/output.mbtiles', 'path/to/input.mbtiles', {
minzoom: 1,
basezoom: 10,
aggregations: __filename, // this can be any file that exports an `aggregations` object like the one below
postAggregations: __filename // same for this
}, function (err) {
if (err) { throw err }
console.log('Finished!')
This yields features that look like:
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-111.09375,
40.97989806962016
],
[
-111.09375,
40.9964840143779
],
[
-111.07177734375,
40.9964840143779
],
[
-111.07177734375,
40.97989806962016
],
[
-111.09375,
40.97989806962016
]
]
Build a pyramid of aggregated square-grid features.
Parameters
output string Path to output aggregated mbtiles datainput string Path to the input mbtiles dataopts (Object|Array) Options OR an array of options objects to allow different aggregations/settings for different zoom levels
opts.basezoom number The zoom level at which to find the initial dataopts.inputTiles Array= An array of [z, x, y] tile coordinates to start withopts.gridsize number Number of grid squares per tileopts.aggregations (Object|string) If an object, then it maps layer names to aggregation objects, which themselves map field names to geojson-polygon-aggregate aggregation function names. Each worker will construct the actual aggregation function from geojson-polygon-aggregate by passing it the field name as an argument. If a string, then it's the path of a module that exports a layer to aggregation object map (see #grid for details).opts.postAggregations string= Path to a module mapping layer names to postAggregations objects. See #grid for details.opts.jobs number The number of jobs to run in parallel.done function called with (err) when doneEstimated unpacked size across 62 packages.
9.8 MB+
Includes dependencies.
5.0.4
^3.1.1
3.1.1
^1.1.3
1.3.0
0.0.0
0.1.0
^1.1.1
1.1.2
^2.0.0-beta1
8.0.0
2.1.0