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
npm install --save boost-geospatial-index
var BoostSpatialIndex = require('boost-geospatial-index');
var bsi = new BoostSpatialIndex();
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 |
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 |
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 |
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 |
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 |
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 |
Returns: boolean
Argument | Type | Description |
---|---|---|
id |
string | shape unique identifier |
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' ]
Here are some features we might add in the future:
- add support for polygons with inner holes
- 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/
This library is published under Apache 2 License.