Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/klarna/geofences-reducer
Reduces overlapping geofences
https://github.com/klarna/geofences-reducer
circular geofence geohash latitude longitude overlapping radius reducer typescript
Last synced: about 1 month ago
JSON representation
Reduces overlapping geofences
- Host: GitHub
- URL: https://github.com/klarna/geofences-reducer
- Owner: klarna
- License: apache-2.0
- Created: 2022-06-24T12:33:06.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-09-29T08:52:50.000Z (about 1 year ago)
- Last Synced: 2024-04-27T03:43:25.166Z (8 months ago)
- Topics: circular, geofence, geohash, latitude, longitude, overlapping, radius, reducer, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@klarna/geofences-reducer
- Size: 1.17 MB
- Stars: 20
- Watchers: 7
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# Geofences Reducer
> Reduces overlapping geofences.[![Build Status][ci-image]][ci-url]
[![License][license-image]][license-url]
[![Developed at Klarna][klarna-image]][klarna-url]Given a list of circular geofences, this library removes the overlapping items and returns a reduced list that could be used to represent the same area.
## Usage example
### Installation
Via npm:
```sh
npm install @klarna/geofences-reducer --save
```Via yarn:
```sh
yarn add @klarna/geofences-reducer
```### Usage
With JavaScript:
```javascript
const reducer = require('@klarna/geofences-reducer')const geofences = [
{
latitude: 51.51,
longitude: -0.36,
radius: 20000 // in meters
},
{
latitude: 51.51,
longitude: -0.07,
radius: 20000 // in meters
},
{
latitude: 51.6,
longitude: -0.07,
radius: 20000 // in meters
},
{
latitude: 51.51,
longitude: 0.12,
radius: 20000 // in meters
},
{
latitude: 51.15,
longitude: -0.07,
radius: 20000 // in meters
},
{
latitude: 51.72,
longitude: -0.07,
radius: 20000 // in meters
}
]const geofencesReduced = reducer.reduce(geofences)
```With TypeScript:
```typescript
import * as reducer from '@klarna/geofences-reducer'type Geofence = {
latitude: number
longitude: number
radius: number
}const geofences: Geofence[] = [
{
latitude: 51.51,
longitude: -0.36,
radius: 20000 // in meters
},
{
latitude: 51.51,
longitude: -0.07,
radius: 20000 // in meters
},
{
latitude: 51.6,
longitude: -0.07,
radius: 20000 // in meters
},
{
latitude: 51.51,
longitude: 0.12,
radius: 20000 // in meters
},
{
latitude: 51.15,
longitude: -0.07,
radius: 20000 // in meters
},
{
latitude: 51.72,
longitude: -0.07,
radius: 20000 // in meters
}
]const geofencesReduced: Geofence[] = reducer.reduce(geofences)
```Result:
![Geohashes](./docs/images/geofences_reduced.png)
### Optional Configuration
#### Precision
Precision can be customized as follows:
```javascript
const config = {
precision: 5 // 6 by default, accepts 1 to 12
}const geofencesReduced = reducer.reduce(geofences, config)
```## Development setup
Install project dependencies:
```sh
npm install
```Run automated test-suite:
```sh
npm test
```## How to contribute
See our guide on [contributing](.github/CONTRIBUTING.md).
## Release History
See our [changelog](CHANGELOG.md).
## License
Copyright © 2021 Klarna Bank AB
For license details, see the [LICENSE](LICENSE) file in the root of this project.
[ci-image]: https://img.shields.io/badge/build-passing-brightgreen?style=flat-square
[ci-url]: https://github.com/klarna/geofences-reducer/actions
[license-image]: https://img.shields.io/badge/license-Apache%202-blue?style=flat-square
[license-url]: http://www.apache.org/licenses/LICENSE-2.0
[klarna-image]: https://img.shields.io/badge/%20-Developed%20at%20Klarna-black?labelColor=ffb3c7&style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAOCAYAAAAmL5yKAAAAAXNSR0IArs4c6QAAAIRlWElmTU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAALQAAAAAQAAAtAAAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAAABCgAwAEAAAAAQAAAA4AAAAA0LMKiwAAAAlwSFl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