Geofence inclusion and exclusion library
A library to perform point-in-geofence searches. A tiled cache is used to determine inclusion very efficiently, so the library is tailored for create once, query many times uses.
Geofence.inside() should be faster than utils.pointInPolygon: iterations: 1000000, innout: 48ms, pointinpolygon: 747ms
npm install in-n-out
Using the Geofence class you can determine whether a point is inside the geofence or not. Upon construction, the geofence's bounding box is broken down into tiles. The tiles that either intersect or are inside the geofence are tracked in a hash table.
Geofence.inside() queries then use this cache to quickly answer
var InNOut = require'in-n-out';var gf = 00 10 11 01 00 100;gfinside0.50.5; // truegfinside100100; // false
Just like GeoJSON supports interior rings
for polygons, the
Geofence class may also be passed multiple sets of
vertices. If you do, the first set is taken to be the exterior ring, and all
subsequent sets are taken as interior rings ("holes").
The geofence's bbox will be broken down into a granularity x granylarity grid, defaulting to 20x20.
Used to determine which ids are valid for a given location, based on the whiteout and blackout geofence rules provided for each id. A typical use case is geofence triggers for loccations, offering location based services or denying services based on location.
var InNOut = require'in-n-out';var whiteoutGf = 00 10 11 01 00;var blackoutGf = 0.50 10 11 0.51 0.5 0;var gfGroup = ;gfGroupadd1 whiteoutGf blackoutGf;gfGroupgetValidKeys0.1 0.1; //  - Included by whiteoutgfGroupgetValidKeys0.6 0.6; //  - Excluded by blackoutgfGroupgetValidKeys100 100; //  - Excluded by whiteout
The inclusion logic is as follows:
Passing null for the geofence arrays is the same as
This provides a relatively primitive caching mechanism which allows you to bypass tile creation for identical geofences. It's basically a drop-in replacement for
new Geofence(). It keeps all geofences around so if you use many of them you'll run out of memory.
var geofenceCache = ;var geo = geofenceCachegetGeo00 10 11 01 00;
Copyright (C) 2013 by Uber Technologies, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.