From 263a1b9e5f0c28dcdd1b4c2da382176e3a584ad6 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Thu, 4 May 2017 10:25:53 -0700 Subject: [PATCH] Add sample filter to limit tiles to a bounding box --- README.md | 9 +++++++++ filters/limit-tiles-to-bbox | 27 +++++++++++++++++++++++++++ man/tippecanoe.1 | 13 +++++++++++++ 3 files changed, 49 insertions(+) create mode 100755 filters/limit-tiles-to-bbox diff --git a/README.md b/README.md index 93e26ea6..ef5ba87f 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,7 @@ resolution is obtained than by using a smaller _maxzoom_ or _detail_. The pre- and post-filter commands allow you to do optional filtering or transformation on the features of each tile as it is created. They are shell commands, run with the zoom level, X, and Y as the `$1`, `$2`, and `$3` arguments. +Future versions of Tippecanoe may add additional arguments for more context. The features are provided to the filter as a series of newline-delimited GeoJSON objects on the standard input, and `tippecanoe` expects to read another @@ -243,6 +244,14 @@ contain `index`, `sequence`, and `extent` elements, which must be passed through ``` tippecanoe -o countries.mbtiles -z5 -C 'mkdir -p tiles/$1/$2; tee tiles/$1/$2/$3.geojson' ne_10m_admin_0_countries.json +``` + + * Make a tileset of the Natural Earth countries to zoom level 5, but including only those tiles that + intersect the [bounding box of Germany](https://www.flickr.com/places/info/23424829). + (The `limit-tiles-to-bbox` script is [in the Tippecanoe source directory](filters/limit-tiles-to-bbox)].) + +``` +tippecanoe -o countries.mbtiles -z5 -C './filters/limit-tiles-to-bbox 5.8662 47.2702 15.0421 55.0581 $*' ne_10m_admin_0_countries.json ``` Environment diff --git a/filters/limit-tiles-to-bbox b/filters/limit-tiles-to-bbox new file mode 100755 index 00000000..d34e2296 --- /dev/null +++ b/filters/limit-tiles-to-bbox @@ -0,0 +1,27 @@ +#!/usr/bin/perl + +use Math::Trig; +use strict; + +# http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames +sub getTileNumber { + my ($lat, $lon, $zoom) = @_; + my $xtile = int(($lon + 180) / 360 * 2 ** $zoom); + my $ytile = int((1 - log(tan(deg2rad($lat)) + sec(deg2rad($lat))) / pi) / 2 * 2 ** $zoom); + return ($xtile, $ytile); +} + +my ($minlon, $minlat, $maxlon, $maxlat, $z, $x, $y) = @ARGV; + +my ($x1, $y1) = getTileNumber($maxlat, $minlon, $z); +my ($x2, $y2) = getTileNumber($minlat, $maxlon, $z); + +if ($x >= $x1 && $x <= $x2 && $y >= $y1 && $y <= $y2) { + while () { + print; + } +} else { + while () { + + } +} diff --git a/man/tippecanoe.1 b/man/tippecanoe.1 index 5228a874..bd02431f 100644 --- a/man/tippecanoe.1 +++ b/man/tippecanoe.1 @@ -273,6 +273,7 @@ If you don't specify, it will use \fB\fC/tmp\fR\&. .PP The pre\- and post\-filter commands allow you to do optional filtering or transformation on the features of each tile as it is created. They are shell commands, run with the zoom level, X, and Y as the \fB\fC$1\fR, \fB\fC$2\fR, and \fB\fC$3\fR arguments. +Future versions of Tippecanoe may add additional arguments for more context. .PP The features are provided to the filter as a series of newline\-delimited GeoJSON objects on the standard input, and \fB\fCtippecanoe\fR expects to read another @@ -298,6 +299,18 @@ to files in a \fB\fCtiles/z/x/y.geojson\fR directory hierarchy. tippecanoe \-o countries.mbtiles \-z5 \-C 'mkdir \-p tiles/$1/$2; tee tiles/$1/$2/$3.geojson' ne_10m_admin_0_countries.json .fi .RE +.RS +.IP \(bu 2 +Make a tileset of the Natural Earth countries to zoom level 5, but including only those tiles that +intersect the bounding box of Germany \[la]https://www.flickr.com/places/info/23424829\[ra]\&. +(The \fB\fClimit\-tiles\-to\-bbox\fR script is in the Tippecanoe source directory \[la]filters/limit-tiles-to-bbox\[ra]].) +.RE +.PP +.RS +.nf +tippecanoe \-o countries.mbtiles \-z5 \-C './filters/limit\-tiles\-to\-bbox 5.8662 47.2702 15.0421 55.0581 $*' ne_10m_admin_0_countries.json +.fi +.RE .SH Environment .PP Tippecanoe ordinarily uses as many parallel threads as the operating system claims that CPUs are available.