@turf/centroid 6.0.0 → 6.0.2
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 +14 -3
- package/index.js +5 -3
- package/package.json +6 -3
- package/index.ts +0 -32
package/README.md
CHANGED
|
@@ -9,8 +9,9 @@ This lessens the effect of small islands and artifacts when calculating the cent
|
|
|
9
9
|
|
|
10
10
|
**Parameters**
|
|
11
11
|
|
|
12
|
-
- `geojson` **[GeoJSON]
|
|
13
|
-
- `
|
|
12
|
+
- `geojson` **[GeoJSON][1]** GeoJSON to be centered
|
|
13
|
+
- `options` **[Object][2]** Optional Parameters (optional, default `{}`)
|
|
14
|
+
- `options.properties` **[Object][2]** an Object that is used as the [Feature][3]'s properties (optional, default `{}`)
|
|
14
15
|
|
|
15
16
|
**Examples**
|
|
16
17
|
|
|
@@ -23,7 +24,17 @@ var centroid = turf.centroid(polygon);
|
|
|
23
24
|
var addToMap = [polygon, centroid]
|
|
24
25
|
```
|
|
25
26
|
|
|
26
|
-
Returns **[Feature]
|
|
27
|
+
Returns **[Feature][4]<[Point][5]>** the centroid of the input features
|
|
28
|
+
|
|
29
|
+
[1]: https://tools.ietf.org/html/rfc7946#section-3
|
|
30
|
+
|
|
31
|
+
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
32
|
+
|
|
33
|
+
[3]: https://tools.ietf.org/html/rfc7946#section-3.2
|
|
34
|
+
|
|
35
|
+
[4]: https://tools.ietf.org/html/rfc7946#section-3.2
|
|
36
|
+
|
|
37
|
+
[5]: https://tools.ietf.org/html/rfc7946#section-3.1.2
|
|
27
38
|
|
|
28
39
|
<!-- This file is automatically generated. Please don't edit it directly:
|
|
29
40
|
if you find an error, edit the source file (likely index.js), and re-run
|
package/index.js
CHANGED
|
@@ -8,7 +8,8 @@ var helpers_1 = require("@turf/helpers");
|
|
|
8
8
|
*
|
|
9
9
|
* @name centroid
|
|
10
10
|
* @param {GeoJSON} geojson GeoJSON to be centered
|
|
11
|
-
* @param {Object} [
|
|
11
|
+
* @param {Object} [options={}] Optional Parameters
|
|
12
|
+
* @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties
|
|
12
13
|
* @returns {Feature<Point>} the centroid of the input features
|
|
13
14
|
* @example
|
|
14
15
|
* var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
|
|
@@ -18,7 +19,8 @@ var helpers_1 = require("@turf/helpers");
|
|
|
18
19
|
* //addToMap
|
|
19
20
|
* var addToMap = [polygon, centroid]
|
|
20
21
|
*/
|
|
21
|
-
function centroid(geojson,
|
|
22
|
+
function centroid(geojson, options) {
|
|
23
|
+
if (options === void 0) { options = {}; }
|
|
22
24
|
var xSum = 0;
|
|
23
25
|
var ySum = 0;
|
|
24
26
|
var len = 0;
|
|
@@ -27,6 +29,6 @@ function centroid(geojson, properties) {
|
|
|
27
29
|
ySum += coord[1];
|
|
28
30
|
len++;
|
|
29
31
|
});
|
|
30
|
-
return helpers_1.point([xSum / len, ySum / len], properties);
|
|
32
|
+
return helpers_1.point([xSum / len, ySum / len], options.properties);
|
|
31
33
|
}
|
|
32
34
|
exports.default = centroid;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/centroid",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.2",
|
|
4
4
|
"description": "turf centroid module",
|
|
5
5
|
"main": "index",
|
|
6
|
+
"types": "index.d.ts",
|
|
6
7
|
"files": [
|
|
7
8
|
"index.js",
|
|
8
|
-
"index.ts"
|
|
9
|
+
"index.d.ts"
|
|
9
10
|
],
|
|
10
11
|
"scripts": {
|
|
11
12
|
"prepare": "tsc",
|
|
@@ -37,7 +38,9 @@
|
|
|
37
38
|
"load-json-file": "*",
|
|
38
39
|
"typescript": "*",
|
|
39
40
|
"tape": "*",
|
|
40
|
-
"write-json-file": "*"
|
|
41
|
+
"write-json-file": "*",
|
|
42
|
+
"tslint": "*",
|
|
43
|
+
"@types/tape": "*"
|
|
41
44
|
},
|
|
42
45
|
"dependencies": {
|
|
43
46
|
"@turf/helpers": "6.x",
|
package/index.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { coordEach } from '@turf/meta';
|
|
2
|
-
import { point, AllGeoJSON, Feature, Point, Properties } from '@turf/helpers';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Takes one or more features and calculates the centroid using the mean of all vertices.
|
|
6
|
-
* This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.
|
|
7
|
-
*
|
|
8
|
-
* @name centroid
|
|
9
|
-
* @param {GeoJSON} geojson GeoJSON to be centered
|
|
10
|
-
* @param {Object} [properties={}] an Object that is used as the {@link Feature}'s properties
|
|
11
|
-
* @returns {Feature<Point>} the centroid of the input features
|
|
12
|
-
* @example
|
|
13
|
-
* var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
|
|
14
|
-
*
|
|
15
|
-
* var centroid = turf.centroid(polygon);
|
|
16
|
-
*
|
|
17
|
-
* //addToMap
|
|
18
|
-
* var addToMap = [polygon, centroid]
|
|
19
|
-
*/
|
|
20
|
-
function centroid(geojson: AllGeoJSON, properties?: Properties) {
|
|
21
|
-
let xSum = 0;
|
|
22
|
-
let ySum = 0;
|
|
23
|
-
let len = 0;
|
|
24
|
-
coordEach(geojson, function (coord) {
|
|
25
|
-
xSum += coord[0];
|
|
26
|
-
ySum += coord[1];
|
|
27
|
-
len++;
|
|
28
|
-
});
|
|
29
|
-
return point([xSum / len, ySum / len], properties);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default centroid;
|