# plastic-geo-distance

> Geographic Distance Utilities

Latest version **1.0.0** (published 2017-10-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install plastic-geo-distance
pnpm add plastic-geo-distance
yarn add plastic-geo-distance
bun add plastic-geo-distance
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-10-08 |
| First published | 2017-10-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Murray Lisook |
| Maintainers | mlisook |
| Keywords | geo, distance, geographic, geographic distance, center, geographic center, center of distance |

## Links

- npm: https://www.npmjs.com/package/plastic-geo-distance
- Repository: https://github.com/mlisook/plastic-geo-distance
- Homepage: https://github.com/mlisook/plastic-geo-distance#readme
- Issues: https://github.com/mlisook/plastic-geo-distance/issues
- npm.io page: https://npm.io/package/plastic-geo-distance

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-10-08

## README

# plastic-geo-distance
A collection of geographic distance related utility functions.

Provides the following methods:
* Determine the bounding rectangle given a point and distance.
* Distance between two points,
* Midpoint of an array of lat/lng
* Center of minimum distance for an array of lat/lng

## Types
* point:` {lat: number, lng: number}` in degrees
* bounds: `{minLat: number, maxLat: number, minLng: number, maxLng: number}` in degrees

## Constructor(units: string)
Create a new instance by providing the units you are using:
* "Miles"
* "Kilometers"

Only the first character is used.
```js
const plasticGeo = new PlasticGeoDistance('k');
```
## Methods
### bounds(distance, point)
Based on the technique by [Jan Matuschek](http://JanMatuschek.de/LatitudeLongitudeBoundingCoordinates).

Returns an object: 
```js
{minLat: number, maxLat: number, minLng: number, maxLng: number}
```

### distance(point1, point2)
Uses the Haversine formula - [credit](http://www.movable-type.co.uk/scripts/latlong.html)

Returns the distance between two points.

### isInBounds(point, bounds)
Determining if a point is within a bounding rectangle is slightly more complex than it appears initially - bounds may encompass 0 degrees or 180 degrees longitude.  This function handles this slight complexity.

Returns `true` if the point is withing the given bounding rectangle ( {minLat, maxLat, minLng, maxLng}), otherwise, `false`.

### computeMidpoint(points Array<{lat:,lng:}>) 
Returns a point that is the geographic center of an array of lat/lng objects (center of gravity).

### computeMinimumDistancePoint(points Array<{lat:,lng:}>)
Adapted from http://www.geomidpoint.com/calculation.html - B. Center of minimum distance

Returns an object: 
```js
{ point: { lat: number, lng: number}, avgDist: number, totalDist: number }
```

`point` is the lat/lng with the minimum total distance to each point in the `points` array, to within less than 0.1 miles (0.161 kilometers).

## Tests
Run test suite with `npm test`.

## Issues
Please submit issues through github at [mlisook plastic-geo-distance issues](https://github.com/mlisook/plastic-geo-distance/issues).

## Contributions
Contributions are welcome and appreciated.

## License

MIT

---
_Source: https://npm.io/package/plastic-geo-distance · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
