npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

boost-geospatial-index

v1.2.0

Published

A bridge to the C++ boost::geometry library, allowing to index and query geospatial shapes

Downloads

1,807

Readme

boost-geospatial-index

Stores and indexes geospatial shapes and exposes query methods.
Shapes can overlap.

This library is used by Kuzzle's real-time engine and is focused on query performances:

  • shapes are indexed using a R* tree ("slow" insertion, very fast query time)
  • based on the C++ boost::geometry library
  • pure C++ module
  • no dependencies

Table of content

Install

npm install --save boost-geospatial-index

API

Creating a new index

var BoostSpatialIndex = require('boost-geospatial-index');

var bsi = new BoostSpatialIndex();

Adding shapes to the index

addBoundingBox(id, min_lat, min_lon, max_lat, max_lon)

Returns: boolean

| Argument | Type | Description | |----------|------|-------------| | id | string | shape unique identifier | | min_lat | number | bottom side of the bounding box | | min_lon | number | left side of the bounding box | | max_lat | number | top side of the bounding box | | max_lon | number | right side of the bounding box |

addCircle(id, lat, lon, radius)

Returns: boolean

| Argument | Type | Description | |----------|------|-------------| | id | string | shape unique identifier | | lat | number | y coordinate of the circle's center | | lon | number | x coordinate of the circle's center | | radius | number | radius of the circle, in meters |

addAnnulus(id, lat, lon, outer, inner)

Returns: boolean

| Argument | Type | Description | |----------|------|-------------| | id | string | shape unique identifier | | lat | number | y coordinate of the annulus' center | | lon | number | x coordinate of the annulus' center | | outer | number | outer radius of the annulus, in meters | | inner | number | inner radius of the annulus, in meters |

addPolygon(id, points)

Creates an open polygon (automatically closed by the library).

Returns: boolean

| Argument | Type | Description | |----------|------|-------------| | id | string | shape unique identifier | | points | array | array of arrays of [lat, lon] points |

Querying the index

queryPoint(lat, lon)

Gets all shapes containing the provided point coordinates. Shapes matching the provided point exactly on their borders or corners are also returned.

If no shape match, an empty array is returned.

Returns: array of shape ids

| Argument | Type | Description | |----------|------|-------------| | lat | number | y coordinate | | lon | number | x coordinate |

queryIntersect(points)

Gets all shapes intersecting the polygon created from the list of point coordinates provided. Shapes partially covered by the polygon also returned.

If no shape match, an empty array is returned.

Returns: array of shape ids

| Argument | Type | Description | |----------|------|-------------| | points | array | array of arrays of [lat, lon] points |

Removing a shape from the index

remove(id)

Returns: boolean

| Argument | Type | Description | |----------|------|-------------| | id | string | shape unique identifier |

Example

var BoostSpatialIndex = require('boost-geospatial-index');

var bsi = new BoostSpatialIndex();

bsi.addBoundingBox('Montpellier, France', 43.5810609, 3.8433703, 43.6331979, 3.9282093);
bsi.addPolygon('Montpellier Millenaire', [
  [43.6021299, 3.8989713],
  [43.6057389, 3.8968173],
  [43.6092889, 3.8970423],
  [43.6100359, 3.9040853],
  [43.6069619, 3.9170343],
  [43.6076479, 3.9230133],
  [43.6038779, 3.9239153],
  [43.6019189, 3.9152403],
  [43.6036049, 3.9092313]
]);
bsi.addAnnulus('Around Kuzzle HQ', 43.6073913, 3.9109057, 1500, 1);
bsi.addCircle('Montpellier Airport', 43.5764455, 3.948711, 2000);

console.log('Querying Kuzzle HQ: ', bsi.queryPoint(43.6073913, 3.9109057));
console.log('Kuzzle team favorite pub:', bsi.queryPoint(43.6002203, 3.897105));
console.log('Hangout spots:', bsi.queryIntersect([
            [43.6072203, 3.9],
            [43.607,5.900],
            [44.609000, 5.90000],
            [44.605,3.9]
            ]));

Result:

Querying Kuzzle HQ:  [ 'Montpellier, France', 'Montpellier Millenaire' ]
Kuzzle team favorite pub: [ 'Montpellier, France', 'Around Kuzzle HQ' ]
Hangout spots: [ 'Montpellier, France',
  'Montpellier Millenaire',
  'Around Kuzzle HQ' ]

TODO

Here are some features we might add in the future:

  • add support for polygons with inner holes

Update Boost headers

  • rm -rf boost-geospatial-index/include/boost
  • Download last boost version : https://www.boost.org/users/download/
  • Unzip then follow this steps
  • ./bootstrap.sh
  • ./b2 tools/bcp
  • ./dist/bin/bcp boost/geometry.hpp boost-geospatial-index/include/

License

This library is published under Apache 2 License.