Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mason_packages
node_modules
build
.toolchain
.mason
.git
local.env
lib/binding
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ before_script:
# For reference, the default travis behavior which we override comes from https://github.com/travis-ci/travis-build/blob/e5a45cbf49e0d9e27398e76e5f25dd7706feb6aa/lib/travis/build/script/node_js.rb#L62-L69.
script: []

# the matrix allows you to specify different operating systems and environments to
# the matrix allows you to specify different operating systems and environments to
# run your tests and build binaries
matrix:
include:
Expand Down Expand Up @@ -83,6 +83,7 @@ matrix:
before_script:
- export LD_PRELOAD=${MASON_LLVM_RT_PRELOAD}
- export ASAN_OPTIONS=fast_unwind_on_malloc=0:${ASAN_OPTIONS}
- export LSAN_OPTIONS=verbosity=1:log_threads=1
- npm test
- unset LD_PRELOAD
# after successful tests, publish binaries if specified in commit message
Expand Down Expand Up @@ -142,4 +143,4 @@ matrix:
# and get in the habit of running these locally before committing)
- make tidy
# Overrides `script`, no need to run tests
before_script:
before_script:
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ubuntu:16.04

# docker build -t vtquery .
# docker run -it vtquery

RUN apt-get update -y && \
apt-get install -y build-essential bash curl git-core ca-certificates software-properties-common vim python-software-properties --no-install-recommends

RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
apt-get update -y

RUN curl https://nodejs.org/dist/v4.8.4/node-v4.8.4-linux-x64.tar.gz | tar zxC /usr/local --strip-components=1

ENV PATH=/usr/local/src/mason_packages/.link/bin:${PATH} CXX=clang++
WORKDIR /usr/local/src
COPY ./ ./

RUN ./scripts/setup.sh --config local.env
RUN /bin/bash -c "source local.env && make"
91 changes: 57 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,33 @@ Get the closest features from a longitude/latitude in a set of vector tile buffe
The two major use cases for this library are:

1. To get a list of the features closest to a query point
2. Point in polygon checks
2. Point in polygon checks (`radius=0`)

# API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

## vtquery

**Parameters**

- `tiles` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** an array of tile objects with `buffer`, `z`, `x`, and `y` values
- `LngLat` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** a query point of longitude and latitude to query, `[lng, lat]`
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?**
- `options.radius` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the radius to query for features. If your radius is larger than
the extent of an individual tile, include multiple nearby buffers to collect a realstic list of features (optional, default `0`)
- `options.results` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of results/features returned from the query. (optional, default `5`)
- `options.layers` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>?** an array of layer string names to query from. Default is all layers.
- `options.geometry` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** only return features of a particular geometry type. Can be `point`, `linestring`, or `polygon`.
Defaults to all geometry types.

**Examples**

```javascript
const vtquery = require('@mapbox/vtquery');

vtquery(tiles, lnglat, options, callback);
```

# Response object

Expand Down Expand Up @@ -55,29 +81,13 @@ Here's an example response
}
```

# API

## vtquery

**Parameters**
## Point in polygon queries

- `tiles` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).&lt;[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** an array of tile objects with `buffer`, `z`, `x`, and `y` values
- `LngLat` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).&lt;[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** a query point of longitude and latitude to query, `[lng, lat]`
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)=**
- `options.radius` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)=** the radius to query for features. If your radius is larger than
the extent of an individual tile, include multiple nearby buffers to collect a realstic list of features (optional, default `0`)
- `options.results` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)=** the number of results/features returned from the query. (optional, default `5`)
- `options.layers` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).&lt;[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>=** an array of layer string names to query from. Default is all layers.
- `options.geometry` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)=** only return features of a particular geometry type. Can be `point`, `linestring`, or `polygon`.
Defaults to all geometry types.
To perform a "point in polygon" query, set your radius value to `0`. This will only return polygons that your query point is _within_.

**Examples**
GOTCHA 1: Be aware of the number of results you are returning - there may be overlapping polygons in a tile, especially if you are querying multiple layers. If a query point exists within multiple polygons there is no way to sort them so they come back in the order they were queried. If there are _more_ results than your `numResults` value specifies, they will just be cut off once the query hits the maximum number of results.

```javascript
const vtquery = require('@mapbox/vtquery');

vtquery(tiles, lnglat, options, callback);
```
GOTCHA 2: Any query point that exists _directly_ along an edge of a polygon will _not_ return.

# Develop

Expand Down Expand Up @@ -105,26 +115,39 @@ npm install -g documentation
npm run docs
```

To install and test on a linux instance, you can use the Dockerfile provided.

```shell
# build the image
docker build -t vtquery .

# run it - this will put you inside the image
docker run -it vtquery

# run tests
make test

# edit files - helpful for debugging
vim src/vtquery.cpp
```


# Benchmarks

Benchmarks can be run with the bench/vtquery.bench.js script to test vtquery against common real-world fixtures (provided by mvt-fixtures). When making changes in a pull request, please provide the benchmarks from the master branch and the HEAD of your current branch. You can control the `concurrency` and `iterations` of the benchmarks with the following command:

```
node bench/vtquery.bench.js --iterations 1000 --concurrency 5
```
node bench/vtquery.bench.js --iterations 1000 --concurrency 5

And the output will show how many times the library was able to execute per second, per fixture:

```
1: 9 tiles, chicago, radius 1000 ... 191 runs/s (5240ms)
2: 9 tiles, chicago, only points ... 3257 runs/s (307ms)
3: mbx streets no radius ... 4049 runs/s (247ms)
4: mbx streets 2000 radius ... 240 runs/s (4159ms)
5: mbx streets only points ... 4673 runs/s (214ms)
6: mbx streets only linestrings ... 286 runs/s (3499ms)
7: mbx streets only polys ... 2801 runs/s (357ms)
8: complex multipolygon ... 1253 runs/s (798ms)
```
1: 9 tiles, chicago, radius 1000 ... 191 runs/s (5240ms)
2: 9 tiles, chicago, only points ... 3257 runs/s (307ms)
3: mbx streets no radius ... 4049 runs/s (247ms)
4: mbx streets 2000 radius ... 240 runs/s (4159ms)
5: mbx streets only points ... 4673 runs/s (214ms)
6: mbx streets only linestrings ... 286 runs/s (3499ms)
7: mbx streets only polys ... 2801 runs/s (357ms)
8: complex multipolygon ... 1253 runs/s (798ms)

# Viz

Expand Down
9 changes: 5 additions & 4 deletions scripts/install_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ function install() {
./scripts/setup.sh --config local.env
source local.env

install geometry 0.9.2
install geometry 96d3505
install variant 1.1.4
install vtzero 556fac5
install protozero ccf6c39
install spatial-algorithms 2904283
install vtzero 1c38ce7
install protozero 1.6.0
install spatial-algorithms cdda174
install boost 1.65.1
install cheap-ruler 2.5.3
install vector-tile 0390175
2 changes: 1 addition & 1 deletion scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -eu
set -o pipefail

export MASON_RELEASE="${MASON_RELEASE:-469edc8}"
export MASON_RELEASE="${MASON_RELEASE:-f4c9c09}"
export MASON_LLVM_RELEASE="${MASON_LLVM_RELEASE:-5.0.0}"

PLATFORM=$(uname | tr A-Z a-z)
Expand Down
64 changes: 0 additions & 64 deletions src/geometry_processors.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ mapbox::geometry::point<double> convert_vt_to_ll(std::uint32_t extent,
std::uint32_t z,
std::uint32_t x,
std::uint32_t y,
mapbox::geometry::algorithms::closest_point_info<std::int64_t> cp_info) {
mapbox::geometry::algorithms::closest_point_info cp_info) {
double z2 = static_cast<double>(static_cast<std::int64_t>(1) << z);
double ex = static_cast<double>(extent);
double size = ex * z2;
Expand Down
Loading