@turf/centroid 6.4.0 → 7.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/es/index.js +7 -9
- package/dist/js/index.d.ts +5 -5
- package/dist/js/index.js +8 -10
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
## centroid
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.
|
|
7
|
+
Computes the centroid as the mean of all vertices within the object.
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
### Parameters
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- `options.properties` **[Object][2]** an Object that is used as the [Feature][3]'s properties (optional, default `{}`)
|
|
11
|
+
* `geojson` **[GeoJSON][1]** GeoJSON to be centered
|
|
12
|
+
* `options` **[Object][2]** Optional Parameters (optional, default `{}`)
|
|
15
13
|
|
|
16
|
-
**
|
|
14
|
+
* `options.properties` **[Object][2]** an Object that is used as the [Feature][3]'s properties (optional, default `{}`)
|
|
15
|
+
|
|
16
|
+
### Examples
|
|
17
17
|
|
|
18
18
|
```javascript
|
|
19
19
|
var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
|
|
@@ -24,7 +24,7 @@ var centroid = turf.centroid(polygon);
|
|
|
24
24
|
var addToMap = [polygon, centroid]
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
Returns **[Feature][4]
|
|
27
|
+
Returns **[Feature][4]<[Point][5]>** the centroid of the input object
|
|
28
28
|
|
|
29
29
|
[1]: https://tools.ietf.org/html/rfc7946#section-3
|
|
30
30
|
|
package/dist/es/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { coordEach } from "@turf/meta";
|
|
2
1
|
import { point } from "@turf/helpers";
|
|
2
|
+
import { coordEach } from "@turf/meta";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.
|
|
4
|
+
* Computes the centroid as the mean of all vertices within the object.
|
|
6
5
|
*
|
|
7
6
|
* @name centroid
|
|
8
7
|
* @param {GeoJSON} geojson GeoJSON to be centered
|
|
9
8
|
* @param {Object} [options={}] Optional Parameters
|
|
10
9
|
* @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties
|
|
11
|
-
* @returns {Feature<Point>} the centroid of the input
|
|
10
|
+
* @returns {Feature<Point>} the centroid of the input object
|
|
12
11
|
* @example
|
|
13
12
|
* var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
|
|
14
13
|
*
|
|
@@ -17,11 +16,10 @@ import { point } from "@turf/helpers";
|
|
|
17
16
|
* //addToMap
|
|
18
17
|
* var addToMap = [polygon, centroid]
|
|
19
18
|
*/
|
|
20
|
-
function centroid(geojson, options) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var len = 0;
|
|
19
|
+
function centroid(geojson, options = {}) {
|
|
20
|
+
let xSum = 0;
|
|
21
|
+
let ySum = 0;
|
|
22
|
+
let len = 0;
|
|
25
23
|
coordEach(geojson, function (coord) {
|
|
26
24
|
xSum += coord[0];
|
|
27
25
|
ySum += coord[1];
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Feature, GeoJsonProperties, Point } from "geojson";
|
|
2
|
+
import { AllGeoJSON } from "@turf/helpers";
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
* This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.
|
|
4
|
+
* Computes the centroid as the mean of all vertices within the object.
|
|
5
5
|
*
|
|
6
6
|
* @name centroid
|
|
7
7
|
* @param {GeoJSON} geojson GeoJSON to be centered
|
|
8
8
|
* @param {Object} [options={}] Optional Parameters
|
|
9
9
|
* @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties
|
|
10
|
-
* @returns {Feature<Point>} the centroid of the input
|
|
10
|
+
* @returns {Feature<Point>} the centroid of the input object
|
|
11
11
|
* @example
|
|
12
12
|
* var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
|
|
13
13
|
*
|
|
@@ -16,7 +16,7 @@ import { AllGeoJSON, Feature, Point, Properties } from "@turf/helpers";
|
|
|
16
16
|
* //addToMap
|
|
17
17
|
* var addToMap = [polygon, centroid]
|
|
18
18
|
*/
|
|
19
|
-
declare function centroid<P =
|
|
19
|
+
declare function centroid<P = GeoJsonProperties>(geojson: AllGeoJSON, options?: {
|
|
20
20
|
properties?: P;
|
|
21
21
|
}): Feature<Point, P>;
|
|
22
22
|
export default centroid;
|
package/dist/js/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const helpers_1 = require("@turf/helpers");
|
|
4
|
+
const meta_1 = require("@turf/meta");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.
|
|
6
|
+
* Computes the centroid as the mean of all vertices within the object.
|
|
8
7
|
*
|
|
9
8
|
* @name centroid
|
|
10
9
|
* @param {GeoJSON} geojson GeoJSON to be centered
|
|
11
10
|
* @param {Object} [options={}] Optional Parameters
|
|
12
11
|
* @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties
|
|
13
|
-
* @returns {Feature<Point>} the centroid of the input
|
|
12
|
+
* @returns {Feature<Point>} the centroid of the input object
|
|
14
13
|
* @example
|
|
15
14
|
* var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
|
|
16
15
|
*
|
|
@@ -19,11 +18,10 @@ var helpers_1 = require("@turf/helpers");
|
|
|
19
18
|
* //addToMap
|
|
20
19
|
* var addToMap = [polygon, centroid]
|
|
21
20
|
*/
|
|
22
|
-
function centroid(geojson, options) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var len = 0;
|
|
21
|
+
function centroid(geojson, options = {}) {
|
|
22
|
+
let xSum = 0;
|
|
23
|
+
let ySum = 0;
|
|
24
|
+
let len = 0;
|
|
27
25
|
meta_1.coordEach(geojson, function (coord) {
|
|
28
26
|
xSum += coord[0];
|
|
29
27
|
ySum += coord[1];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/centroid",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.0",
|
|
4
4
|
"description": "turf centroid module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "git://github.com/Turfjs/turf.git"
|
|
14
14
|
},
|
|
15
|
+
"funding": "https://opencollective.com/turf",
|
|
15
16
|
"publishConfig": {
|
|
16
17
|
"access": "public"
|
|
17
18
|
},
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
"docs": "node ../../scripts/generate-readmes",
|
|
44
45
|
"test": "npm-run-all test:*",
|
|
45
46
|
"test:tape": "ts-node -r esm test.js",
|
|
46
|
-
"test:types": "tsc --esModuleInterop --noEmit types.ts"
|
|
47
|
+
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@types/tape": "*",
|
|
@@ -59,8 +60,9 @@
|
|
|
59
60
|
"write-json-file": "*"
|
|
60
61
|
},
|
|
61
62
|
"dependencies": {
|
|
62
|
-
"@turf/helpers": "^
|
|
63
|
-
"@turf/meta": "^
|
|
63
|
+
"@turf/helpers": "^7.0.0-alpha.0",
|
|
64
|
+
"@turf/meta": "^7.0.0-alpha.0",
|
|
65
|
+
"tslib": "^2.3.0"
|
|
64
66
|
},
|
|
65
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
66
68
|
}
|