1.2.0 • Published 8 months ago

boost-geospatial-index v1.2.0

Weekly downloads
314
License
Apache-2.0
Repository
github
Last release
8 months ago

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

 ArgumentTypeDescription
idstringshape unique identifier
min_latnumberbottom side of the bounding box
min_lonnumberleft side of the bounding box
max_latnumbertop side of the bounding box
max_lonnumberright side of the bounding box
addCircle(id, lat, lon, radius)

Returns: boolean

 ArgumentTypeDescription
idstringshape unique identifier
latnumbery coordinate of the circle's center
lonnumberx coordinate of the circle's center
radiusnumberradius of the circle, in meters
addAnnulus(id, lat, lon, outer, inner)

Returns: boolean

 ArgumentTypeDescription
idstringshape unique identifier
latnumbery coordinate of the annulus' center
lonnumberx coordinate of the annulus' center
outernumberouter radius of the annulus, in meters
innernumberinner radius of the annulus, in meters
addPolygon(id, points)

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

Returns: boolean

 ArgumentTypeDescription
idstringshape unique identifier
pointsarrayarray 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

 ArgumentTypeDescription
latnumbery coordinate
lonnumberx 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

 ArgumentTypeDescription
pointsarrayarray of arrays of lat, lon points

Removing a shape from the index

remove(id)

Returns: boolean

 ArgumentTypeDescription
idstringshape 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.

1.2.0

8 months ago

1.2.0-beta.1

8 months ago

1.2.0-beta.2

8 months ago

1.1.2

1 year ago

1.1.1

2 years ago

1.1.0

4 years ago

1.0.5

5 years ago

1.0.4

6 years ago

1.0.3

7 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago