@turf/centroid 7.0.0-alpha.1 → 7.0.0-alpha.110
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 +4 -9
- package/dist/cjs/index.cjs +28 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{js → cjs}/index.d.ts +6 -4
- package/dist/{es/index.js → esm/index.d.mts} +8 -14
- package/dist/esm/index.mjs +28 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +33 -28
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -32
package/README.md
CHANGED
|
@@ -36,26 +36,21 @@ Returns **[Feature][4]<[Point][5]>** the centroid of the input object
|
|
|
36
36
|
|
|
37
37
|
[5]: https://tools.ietf.org/html/rfc7946#section-3.1.2
|
|
38
38
|
|
|
39
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
40
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
41
|
-
./scripts/generate-readmes in the turf project. -->
|
|
39
|
+
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
|
|
42
40
|
|
|
43
41
|
---
|
|
44
42
|
|
|
45
|
-
This module is part of the [Turfjs project](
|
|
46
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
47
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
48
|
-
PRs and issues.
|
|
43
|
+
This module is part of the [Turfjs project](https://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.
|
|
49
44
|
|
|
50
45
|
### Installation
|
|
51
46
|
|
|
52
|
-
Install this module individually:
|
|
47
|
+
Install this single module individually:
|
|
53
48
|
|
|
54
49
|
```sh
|
|
55
50
|
$ npm install @turf/centroid
|
|
56
51
|
```
|
|
57
52
|
|
|
58
|
-
Or install the
|
|
53
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
59
54
|
|
|
60
55
|
```sh
|
|
61
56
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
var _helpers = require('@turf/helpers');
|
|
6
|
+
var _meta = require('@turf/meta');
|
|
7
|
+
function centroid(geojson, options = {}) {
|
|
8
|
+
let xSum = 0;
|
|
9
|
+
let ySum = 0;
|
|
10
|
+
let len = 0;
|
|
11
|
+
_meta.coordEach.call(void 0,
|
|
12
|
+
geojson,
|
|
13
|
+
function(coord) {
|
|
14
|
+
xSum += coord[0];
|
|
15
|
+
ySum += coord[1];
|
|
16
|
+
len++;
|
|
17
|
+
},
|
|
18
|
+
true
|
|
19
|
+
);
|
|
20
|
+
return _helpers.point.call(void 0, [xSum / len, ySum / len], options.properties);
|
|
21
|
+
}
|
|
22
|
+
__name(centroid, "centroid");
|
|
23
|
+
var turf_centroid_default = centroid;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
exports.centroid = centroid; exports.default = turf_centroid_default;
|
|
28
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AACA,SAAS,aAAyB;AAClC,SAAS,iBAAiB;AAkB1B,SAAS,SACP,SACA,UAEI,CAAC,GACc;AACnB,MAAI,OAAO;AACX,MAAI,OAAO;AACX,MAAI,MAAM;AACV;AAAA,IACE;AAAA,IACA,SAAU,OAAO;AACf,cAAQ,MAAM,CAAC;AACf,cAAQ,MAAM,CAAC;AACf;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACA,SAAO,MAAM,CAAC,OAAO,KAAK,OAAO,GAAG,GAAG,QAAQ,UAAU;AAC3D;AAnBS;AAsBT,IAAO,wBAAQ","sourcesContent":["import { Feature, GeoJsonProperties, Point } from \"geojson\";\nimport { point, AllGeoJSON } from \"@turf/helpers\";\nimport { coordEach } from \"@turf/meta\";\n\n/**\n * Computes the centroid as the mean of all vertices within the object.\n *\n * @name centroid\n * @param {GeoJSON} geojson GeoJSON to be centered\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties\n * @returns {Feature<Point>} the centroid of the input object\n * @example\n * var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);\n *\n * var centroid = turf.centroid(polygon);\n *\n * //addToMap\n * var addToMap = [polygon, centroid]\n */\nfunction centroid<P extends GeoJsonProperties = GeoJsonProperties>(\n geojson: AllGeoJSON,\n options: {\n properties?: P;\n } = {}\n): Feature<Point, P> {\n let xSum = 0;\n let ySum = 0;\n let len = 0;\n coordEach(\n geojson,\n function (coord) {\n xSum += coord[0];\n ySum += coord[1];\n len++;\n },\n true\n );\n return point([xSum / len, ySum / len], options.properties);\n}\n\nexport { centroid };\nexport default centroid;\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AllGeoJSON } from
|
|
1
|
+
import { GeoJsonProperties, Feature, Point } from 'geojson';
|
|
2
|
+
import { AllGeoJSON } from '@turf/helpers';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Computes the centroid as the mean of all vertices within the object.
|
|
5
6
|
*
|
|
@@ -16,7 +17,8 @@ import { AllGeoJSON } from "@turf/helpers";
|
|
|
16
17
|
* //addToMap
|
|
17
18
|
* var addToMap = [polygon, centroid]
|
|
18
19
|
*/
|
|
19
|
-
declare function centroid<P = GeoJsonProperties>(geojson: AllGeoJSON, options?: {
|
|
20
|
+
declare function centroid<P extends GeoJsonProperties = GeoJsonProperties>(geojson: AllGeoJSON, options?: {
|
|
20
21
|
properties?: P;
|
|
21
22
|
}): Feature<Point, P>;
|
|
22
|
-
|
|
23
|
+
|
|
24
|
+
export { centroid, centroid as default };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { GeoJsonProperties, Feature, Point } from 'geojson';
|
|
2
|
+
import { AllGeoJSON } from '@turf/helpers';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Computes the centroid as the mean of all vertices within the object.
|
|
5
6
|
*
|
|
@@ -16,15 +17,8 @@ import { coordEach } from "@turf/meta";
|
|
|
16
17
|
* //addToMap
|
|
17
18
|
* var addToMap = [polygon, centroid]
|
|
18
19
|
*/
|
|
19
|
-
function centroid(geojson, options
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
xSum += coord[0];
|
|
25
|
-
ySum += coord[1];
|
|
26
|
-
len++;
|
|
27
|
-
}, true);
|
|
28
|
-
return point([xSum / len, ySum / len], options.properties);
|
|
29
|
-
}
|
|
30
|
-
export default centroid;
|
|
20
|
+
declare function centroid<P extends GeoJsonProperties = GeoJsonProperties>(geojson: AllGeoJSON, options?: {
|
|
21
|
+
properties?: P;
|
|
22
|
+
}): Feature<Point, P>;
|
|
23
|
+
|
|
24
|
+
export { centroid, centroid as default };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import { point } from "@turf/helpers";
|
|
6
|
+
import { coordEach } from "@turf/meta";
|
|
7
|
+
function centroid(geojson, options = {}) {
|
|
8
|
+
let xSum = 0;
|
|
9
|
+
let ySum = 0;
|
|
10
|
+
let len = 0;
|
|
11
|
+
coordEach(
|
|
12
|
+
geojson,
|
|
13
|
+
function(coord) {
|
|
14
|
+
xSum += coord[0];
|
|
15
|
+
ySum += coord[1];
|
|
16
|
+
len++;
|
|
17
|
+
},
|
|
18
|
+
true
|
|
19
|
+
);
|
|
20
|
+
return point([xSum / len, ySum / len], options.properties);
|
|
21
|
+
}
|
|
22
|
+
__name(centroid, "centroid");
|
|
23
|
+
var turf_centroid_default = centroid;
|
|
24
|
+
export {
|
|
25
|
+
centroid,
|
|
26
|
+
turf_centroid_default as default
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Feature, GeoJsonProperties, Point } from \"geojson\";\nimport { point, AllGeoJSON } from \"@turf/helpers\";\nimport { coordEach } from \"@turf/meta\";\n\n/**\n * Computes the centroid as the mean of all vertices within the object.\n *\n * @name centroid\n * @param {GeoJSON} geojson GeoJSON to be centered\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties\n * @returns {Feature<Point>} the centroid of the input object\n * @example\n * var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);\n *\n * var centroid = turf.centroid(polygon);\n *\n * //addToMap\n * var addToMap = [polygon, centroid]\n */\nfunction centroid<P extends GeoJsonProperties = GeoJsonProperties>(\n geojson: AllGeoJSON,\n options: {\n properties?: P;\n } = {}\n): Feature<Point, P> {\n let xSum = 0;\n let ySum = 0;\n let len = 0;\n coordEach(\n geojson,\n function (coord) {\n xSum += coord[0];\n ySum += coord[1];\n len++;\n },\n true\n );\n return point([xSum / len, ySum / len], options.properties);\n}\n\nexport { centroid };\nexport default centroid;\n"],"mappings":";;;;AACA,SAAS,aAAyB;AAClC,SAAS,iBAAiB;AAkB1B,SAAS,SACP,SACA,UAEI,CAAC,GACc;AACnB,MAAI,OAAO;AACX,MAAI,OAAO;AACX,MAAI,MAAM;AACV;AAAA,IACE;AAAA,IACA,SAAU,OAAO;AACf,cAAQ,MAAM,CAAC;AACf,cAAQ,MAAM,CAAC;AACf;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACA,SAAO,MAAM,CAAC,OAAO,KAAK,OAAO,GAAG,GAAG,QAAQ,UAAU;AAC3D;AAnBS;AAsBT,IAAO,wBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/centroid",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.110+1411d63a7",
|
|
4
4
|
"description": "turf centroid module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,48 +22,53 @@
|
|
|
22
22
|
"geo",
|
|
23
23
|
"gis"
|
|
24
24
|
],
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"type": "commonjs",
|
|
26
|
+
"main": "dist/cjs/index.cjs",
|
|
27
|
+
"module": "dist/esm/index.mjs",
|
|
28
|
+
"types": "dist/cjs/index.d.ts",
|
|
27
29
|
"exports": {
|
|
28
30
|
"./package.json": "./package.json",
|
|
29
31
|
".": {
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/esm/index.d.mts",
|
|
34
|
+
"default": "./dist/esm/index.mjs"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/cjs/index.d.ts",
|
|
38
|
+
"default": "./dist/cjs/index.cjs"
|
|
39
|
+
}
|
|
33
40
|
}
|
|
34
41
|
},
|
|
35
|
-
"types": "dist/js/index.d.ts",
|
|
36
42
|
"sideEffects": false,
|
|
37
43
|
"files": [
|
|
38
44
|
"dist"
|
|
39
45
|
],
|
|
40
46
|
"scripts": {
|
|
41
|
-
"bench": "tsx bench.
|
|
42
|
-
"build": "
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"test": "npm-run-all test:*",
|
|
47
|
-
"test:tape": "tsx test.js",
|
|
47
|
+
"bench": "tsx bench.ts",
|
|
48
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
49
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
50
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
51
|
+
"test:tape": "tsx test.ts",
|
|
48
52
|
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
49
53
|
},
|
|
50
54
|
"devDependencies": {
|
|
51
|
-
"@types/
|
|
52
|
-
"
|
|
55
|
+
"@types/benchmark": "^2.1.5",
|
|
56
|
+
"@types/tape": "^4.2.32",
|
|
57
|
+
"benchmark": "^2.1.4",
|
|
53
58
|
"geojson-fixtures": "*",
|
|
54
|
-
"glob": "
|
|
55
|
-
"load-json-file": "
|
|
56
|
-
"npm-run-all": "
|
|
57
|
-
"tape": "
|
|
58
|
-
"
|
|
59
|
-
"tsx": "
|
|
60
|
-
"typescript": "
|
|
61
|
-
"write-json-file": "
|
|
59
|
+
"glob": "^10.3.10",
|
|
60
|
+
"load-json-file": "^7.0.1",
|
|
61
|
+
"npm-run-all": "^4.1.5",
|
|
62
|
+
"tape": "^5.7.2",
|
|
63
|
+
"tsup": "^8.0.1",
|
|
64
|
+
"tsx": "^4.6.2",
|
|
65
|
+
"typescript": "^5.2.2",
|
|
66
|
+
"write-json-file": "^5.0.0"
|
|
62
67
|
},
|
|
63
68
|
"dependencies": {
|
|
64
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
65
|
-
"@turf/meta": "^7.0.0-alpha.
|
|
66
|
-
"tslib": "^2.
|
|
69
|
+
"@turf/helpers": "^7.0.0-alpha.110+1411d63a7",
|
|
70
|
+
"@turf/meta": "^7.0.0-alpha.110+1411d63a7",
|
|
71
|
+
"tslib": "^2.6.2"
|
|
67
72
|
},
|
|
68
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
|
|
69
74
|
}
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const helpers_1 = require("@turf/helpers");
|
|
4
|
-
const meta_1 = require("@turf/meta");
|
|
5
|
-
/**
|
|
6
|
-
* Computes the centroid as the mean of all vertices within the object.
|
|
7
|
-
*
|
|
8
|
-
* @name centroid
|
|
9
|
-
* @param {GeoJSON} geojson GeoJSON to be centered
|
|
10
|
-
* @param {Object} [options={}] Optional Parameters
|
|
11
|
-
* @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties
|
|
12
|
-
* @returns {Feature<Point>} the centroid of the input object
|
|
13
|
-
* @example
|
|
14
|
-
* var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
|
|
15
|
-
*
|
|
16
|
-
* var centroid = turf.centroid(polygon);
|
|
17
|
-
*
|
|
18
|
-
* //addToMap
|
|
19
|
-
* var addToMap = [polygon, centroid]
|
|
20
|
-
*/
|
|
21
|
-
function centroid(geojson, options = {}) {
|
|
22
|
-
let xSum = 0;
|
|
23
|
-
let ySum = 0;
|
|
24
|
-
let len = 0;
|
|
25
|
-
meta_1.coordEach(geojson, function (coord) {
|
|
26
|
-
xSum += coord[0];
|
|
27
|
-
ySum += coord[1];
|
|
28
|
-
len++;
|
|
29
|
-
}, true);
|
|
30
|
-
return helpers_1.point([xSum / len, ySum / len], options.properties);
|
|
31
|
-
}
|
|
32
|
-
exports.default = centroid;
|