1.0.0 • Published 9 years ago

spatial-mapping v1.0.0

Weekly downloads
6
License
MIT
Repository
github
Last release
9 years ago

spatial-mapping

This module divides an area to buckets and maps 2d coordinates to a unique key. This key can then be used to store users in a hash or a rational database that doesn't have a spatial-query support.

Indexing this column will enable us to query for users in a specific bucket. Also- this module exposes an api to get all the buckets around a specific coordinates, so that we could query for all users in a bucket-size area that doesn't necessarily falls in one whole bucket. Filtering the users that actually falls in the required area will be done by the callback of the requesting function.

An example of using this module can be found in the nodemmo project.

usage

var options = {
  gridUnit: {
    width: 2000,
    height: 500
  }
};

var spatialMapper = require('spatial-mapping')(options);
var x = 10000, y = 4000;
var gridKey = spatialMapper.getKey(x, y);
console.log('gridKey', gridKey); // gridKey [5,8]

var gridIds = spatialMapper.getViewGrids(x, y);
console.log('gridIds', gridIds); // gridIds [ '[4,7]', '[4,8]', '[5,7]', '[5,8]' ]

License

MIT

1.0.0

9 years ago