143 lines
3.5 KiB
Markdown
143 lines
3.5 KiB
Markdown
# @turf/center
|
|
|
|
# center
|
|
|
|
Takes a [Feature](http://geojson.org/geojson-spec.html#feature-objects) or [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) and returns the absolute center point of all features.
|
|
|
|
**Parameters**
|
|
|
|
- `layer` **([Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects))** input features
|
|
|
|
**Examples**
|
|
|
|
```javascript
|
|
var features = {
|
|
"type": "FeatureCollection",
|
|
"features": [
|
|
{
|
|
"type": "Feature",
|
|
"properties": {},
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [-97.522259, 35.4691]
|
|
}
|
|
}, {
|
|
"type": "Feature",
|
|
"properties": {},
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [-97.502754, 35.463455]
|
|
}
|
|
}, {
|
|
"type": "Feature",
|
|
"properties": {},
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [-97.508269, 35.463245]
|
|
}
|
|
}, {
|
|
"type": "Feature",
|
|
"properties": {},
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [-97.516809, 35.465779]
|
|
}
|
|
}, {
|
|
"type": "Feature",
|
|
"properties": {},
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [-97.515372, 35.467072]
|
|
}
|
|
}, {
|
|
"type": "Feature",
|
|
"properties": {},
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [-97.509363, 35.463053]
|
|
}
|
|
}, {
|
|
"type": "Feature",
|
|
"properties": {},
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [-97.511123, 35.466601]
|
|
}
|
|
}, {
|
|
"type": "Feature",
|
|
"properties": {},
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [-97.518547, 35.469327]
|
|
}
|
|
}, {
|
|
"type": "Feature",
|
|
"properties": {},
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [-97.519706, 35.469659]
|
|
}
|
|
}, {
|
|
"type": "Feature",
|
|
"properties": {},
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [-97.517839, 35.466998]
|
|
}
|
|
}, {
|
|
"type": "Feature",
|
|
"properties": {},
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [-97.508678, 35.464942]
|
|
}
|
|
}, {
|
|
"type": "Feature",
|
|
"properties": {},
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [-97.514914, 35.463453]
|
|
}
|
|
}
|
|
]
|
|
};
|
|
|
|
var centerPt = turf.center(features);
|
|
centerPt.properties['marker-size'] = 'large';
|
|
centerPt.properties['marker-color'] = '#000';
|
|
|
|
var resultFeatures = features.features.concat(centerPt);
|
|
var result = {
|
|
"type": "FeatureCollection",
|
|
"features": resultFeatures
|
|
};
|
|
|
|
//=result
|
|
```
|
|
|
|
Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** a Point feature at the absolute center point of all input features
|
|
|
|
<!-- This file is automatically generated. Please don't edit it directly:
|
|
if you find an error, edit the source file (likely index.js), and re-run
|
|
./scripts/generate-readmes in the turf project. -->
|
|
|
|
---
|
|
|
|
This module is part of the [Turfjs project](http://turfjs.org/), an open source
|
|
module collection dedicated to geographic algorithms. It is maintained in the
|
|
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
PRs and issues.
|
|
|
|
### Installation
|
|
|
|
Install this module individually:
|
|
|
|
```sh
|
|
$ npm install @turf/center
|
|
```
|
|
|
|
Or install the Turf module that includes it as a function:
|
|
|
|
```sh
|
|
$ npm install @turf/turf
|
|
```
|