šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

boost-geospatial-index

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boost-geospatial-index

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

1.3.0
latest
Source
npm
Version published
Weekly downloads
1.3K
10.42%
Maintainers
0
Weekly downloads
Ā 
Created
Source

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.

Keywords

rtree

FAQs

Package last updated on 07 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts