# @terraformer/spatial

[![npm][npm-image]][npm-url]
[![travis][travis-image]][travis-url]
[![standard][standard-image]][standard-url]

[npm-image]: https://img.shields.io/npm/v/@terraformer/spatial.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/@terraformer/spatial
[travis-image]: https://app.travis-ci.com/terraformer-js/terraformer.svg?branch=main
[travis-url]: https://app.travis-ci.com/terraformer-js/terraformer
[standard-image]: https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat-square
[standard-url]: http://npm.im/semistandard

> Spatial predicates for GeoJSON.

## Install

```
npm install @terraformer/spatial
```

## API Reference

{{>main}}
* * *

## Usage

### Browser (from CDN)

This package is distributed as a [UMD](https://github.com/umdjs/umd) module and can also be used in AMD based systems or as a global under the `Terraformer` namespace.

```html
<script src="https://unpkg.com/@terraformer/spatial"></script>
```
```js
const input = {
  'type': 'Polygon',
  'coordinates': [
    [ [41.83, 71.01], [56.95, 33.75], [21.79, 36.56], [41.83, 71.01] ]
  ]
};

Terraformer.isConvex(input.coordinates[0]); // true
```

### Node.js

```js
const Terraformer = require('@terraformer/spatial');

Terraformer.isConvex(/* ... */);
```

### ES module in the browser

```html
<script type='module'>
  import { isConvex } from 'https://unpkg.com/@terraformer/spatial?module';

  // look ma, no build step!
  isConvex(/* ... */);
</script>
```

## FAQ

<details>
  <summary>What's the difference between this project and <a href="https://turfjs.org">Turf.js</a>?</summary>

  Both libraries work with GeoJSON and share many similar functions. Turf.js relies on JSTS, and some folks have [found it to be slower](https://github.com/Esri/terraformer/issues/268#issuecomment-196413416). In the past Turf.js did not include predicates like 'within', 'contains' and 'intersects', but that no longer appears to be the case.
</details>

## [Contributing](./CONTRIBUTING.md)

## [LICENSE](https://raw.githubusercontent.com/terraformer-js/terraformer/master/LICENSE)
