@turf/distance-weight 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 CHANGED
@@ -6,29 +6,32 @@
6
6
 
7
7
  calcualte the Minkowski p-norm distance between two features.
8
8
 
9
- **Parameters**
9
+ ### Parameters
10
10
 
11
- - `feature1` point feature
12
- - `feature2` point feature
13
- - `p` p-norm 1=<p<=infinity 1: Manhattan distance 2: Euclidean distance
11
+ * `feature1` **[Feature][1]<[Point][2]>** point feature
12
+ * `feature2` **[Feature][1]<[Point][2]>** point feature
13
+ * `p` p-norm 1=\<p<=infinity 1: Manhattan distance 2: Euclidean distance (optional, default `2`)
14
+
15
+ Returns **[number][3]**
14
16
 
15
17
  ## distanceWeight
16
18
 
17
- **Parameters**
19
+ ### Parameters
20
+
21
+ * `fc` **[FeatureCollection][4]\<any>** FeatureCollection.
22
+ * `options` **[Object][5]?** option object.
18
23
 
19
- - `fc` **[FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3)&lt;any>** FeatureCollection.
20
- - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** option object.
21
- - `options.threshold` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** If the distance between neighbor and
24
+ * `options.threshold` **[number][3]** If the distance between neighbor and
22
25
  target features is greater than threshold, the weight of that neighbor is 0. (optional, default `10000`)
23
- - `options.p` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Minkowski p-norm distance parameter.
24
- 1: Manhattan distance. 2: Euclidean distance. 1=&lt;p&lt;=infinity. (optional, default `2`)
25
- - `options.binary` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If true, weight=1 if d &lt;= threshold otherwise weight=0.
26
- If false, weight=Math.pow(d, alpha). (optional, default `false`)
27
- - `options.alpha` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** distance decay parameter.
26
+ * `options.p` **[number][3]** Minkowski p-norm distance parameter.
27
+ 1: Manhattan distance. 2: Euclidean distance. 1=\<p<=infinity. (optional, default `2`)
28
+ * `options.binary` **[boolean][6]** If true, weight=1 if d <= threshold otherwise weight=0.
29
+ If false, weight=Math.pow(d, alpha). (optional, default `false`)
30
+ * `options.alpha` **[number][3]** distance decay parameter.
28
31
  A big value means the weight decay quickly as distance increases. (optional, default `-1`)
29
- - `options.standardization` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** row standardization. (optional, default `false`)
32
+ * `options.standardization` **[boolean][6]** row standardization. (optional, default `false`)
30
33
 
31
- **Examples**
34
+ ### Examples
32
35
 
33
36
  ```javascript
34
37
  var bbox = [-65, 40, -63, 42];
@@ -36,7 +39,21 @@ var dataset = turf.randomPoint(100, { bbox: bbox });
36
39
  var result = turf.distanceWeight(dataset);
37
40
  ```
38
41
 
39
- Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>>** distance weight matrix.
42
+ Returns **[Array][7]<[Array][7]<[number][3]>>** distance weight matrix.
43
+
44
+ [1]: https://tools.ietf.org/html/rfc7946#section-3.2
45
+
46
+ [2]: https://tools.ietf.org/html/rfc7946#section-3.1.2
47
+
48
+ [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
49
+
50
+ [4]: https://tools.ietf.org/html/rfc7946#section-3.3
51
+
52
+ [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
53
+
54
+ [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
55
+
56
+ [7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
40
57
 
41
58
  <!-- This file is automatically generated. Please don't edit it directly:
42
59
  if you find an error, edit the source file (likely index.js), and re-run
package/dist/es/index.js CHANGED
@@ -7,12 +7,11 @@ import { featureEach } from "@turf/meta";
7
7
  * @param feature2 point feature
8
8
  * @param p p-norm 1=<p<=infinity 1: Manhattan distance 2: Euclidean distance
9
9
  */
10
- export function pNormDistance(feature1, feature2, p) {
11
- if (p === void 0) { p = 2; }
12
- var coordinate1 = getCoord(feature1);
13
- var coordinate2 = getCoord(feature2);
14
- var xDiff = coordinate1[0] - coordinate2[0];
15
- var yDiff = coordinate1[1] - coordinate2[1];
10
+ export function pNormDistance(feature1, feature2, p = 2) {
11
+ const coordinate1 = getCoord(feature1);
12
+ const coordinate2 = getCoord(feature2);
13
+ const xDiff = coordinate1[0] - coordinate2[0];
14
+ const yDiff = coordinate1[1] - coordinate2[1];
16
15
  if (p === 1) {
17
16
  return Math.abs(xDiff) + Math.abs(yDiff);
18
17
  }
@@ -42,34 +41,34 @@ export function pNormDistance(feature1, feature2, p) {
42
41
  */
43
42
  export default function distanceWeight(fc, options) {
44
43
  options = options || {};
45
- var threshold = options.threshold || 10000;
46
- var p = options.p || 2;
47
- var binary = options.binary || false;
48
- var alpha = options.alpha || -1;
49
- var rowTransform = options.standardization || false;
50
- var features = [];
51
- featureEach(fc, function (feature) {
44
+ const threshold = options.threshold || 10000;
45
+ const p = options.p || 2;
46
+ const binary = options.binary || false;
47
+ const alpha = options.alpha || -1;
48
+ const rowTransform = options.standardization || false;
49
+ const features = [];
50
+ featureEach(fc, (feature) => {
52
51
  features.push(centroid(feature));
53
52
  });
54
53
  // computing the distance between the features
55
- var weights = [];
56
- for (var i = 0; i < features.length; i++) {
54
+ const weights = [];
55
+ for (let i = 0; i < features.length; i++) {
57
56
  weights[i] = [];
58
57
  }
59
- for (var i = 0; i < features.length; i++) {
60
- for (var j = i; j < features.length; j++) {
58
+ for (let i = 0; i < features.length; i++) {
59
+ for (let j = i; j < features.length; j++) {
61
60
  if (i === j) {
62
61
  weights[i][j] = 0;
63
62
  }
64
- var dis = pNormDistance(features[i], features[j], p);
63
+ const dis = pNormDistance(features[i], features[j], p);
65
64
  weights[i][j] = dis;
66
65
  weights[j][i] = dis;
67
66
  }
68
67
  }
69
68
  // binary or distance decay
70
- for (var i = 0; i < features.length; i++) {
71
- for (var j = 0; j < features.length; j++) {
72
- var dis = weights[i][j];
69
+ for (let i = 0; i < features.length; i++) {
70
+ for (let j = 0; j < features.length; j++) {
71
+ const dis = weights[i][j];
73
72
  if (dis === 0) {
74
73
  continue;
75
74
  }
@@ -92,11 +91,11 @@ export default function distanceWeight(fc, options) {
92
91
  }
93
92
  }
94
93
  if (rowTransform) {
95
- for (var i = 0; i < features.length; i++) {
96
- var rowSum = weights[i].reduce(function (sum, currentVal) {
94
+ for (let i = 0; i < features.length; i++) {
95
+ const rowSum = weights[i].reduce((sum, currentVal) => {
97
96
  return sum + currentVal;
98
97
  }, 0);
99
- for (var j = 0; j < features.length; j++) {
98
+ for (let j = 0; j < features.length; j++) {
100
99
  weights[i][j] = weights[i][j] / rowSum;
101
100
  }
102
101
  }
@@ -1,4 +1,4 @@
1
- import { Feature, FeatureCollection, Point } from "@turf/helpers";
1
+ import { Feature, FeatureCollection, Point } from "geojson";
2
2
  /**
3
3
  * calcualte the Minkowski p-norm distance between two features.
4
4
  * @param feature1 point feature
package/dist/js/index.js CHANGED
@@ -1,23 +1,20 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var centroid_1 = __importDefault(require("@turf/centroid"));
7
- var invariant_1 = require("@turf/invariant");
8
- var meta_1 = require("@turf/meta");
3
+ const tslib_1 = require("tslib");
4
+ const centroid_1 = tslib_1.__importDefault(require("@turf/centroid"));
5
+ const invariant_1 = require("@turf/invariant");
6
+ const meta_1 = require("@turf/meta");
9
7
  /**
10
8
  * calcualte the Minkowski p-norm distance between two features.
11
9
  * @param feature1 point feature
12
10
  * @param feature2 point feature
13
11
  * @param p p-norm 1=<p<=infinity 1: Manhattan distance 2: Euclidean distance
14
12
  */
15
- function pNormDistance(feature1, feature2, p) {
16
- if (p === void 0) { p = 2; }
17
- var coordinate1 = invariant_1.getCoord(feature1);
18
- var coordinate2 = invariant_1.getCoord(feature2);
19
- var xDiff = coordinate1[0] - coordinate2[0];
20
- var yDiff = coordinate1[1] - coordinate2[1];
13
+ function pNormDistance(feature1, feature2, p = 2) {
14
+ const coordinate1 = invariant_1.getCoord(feature1);
15
+ const coordinate2 = invariant_1.getCoord(feature2);
16
+ const xDiff = coordinate1[0] - coordinate2[0];
17
+ const yDiff = coordinate1[1] - coordinate2[1];
21
18
  if (p === 1) {
22
19
  return Math.abs(xDiff) + Math.abs(yDiff);
23
20
  }
@@ -48,34 +45,34 @@ exports.pNormDistance = pNormDistance;
48
45
  */
49
46
  function distanceWeight(fc, options) {
50
47
  options = options || {};
51
- var threshold = options.threshold || 10000;
52
- var p = options.p || 2;
53
- var binary = options.binary || false;
54
- var alpha = options.alpha || -1;
55
- var rowTransform = options.standardization || false;
56
- var features = [];
57
- meta_1.featureEach(fc, function (feature) {
48
+ const threshold = options.threshold || 10000;
49
+ const p = options.p || 2;
50
+ const binary = options.binary || false;
51
+ const alpha = options.alpha || -1;
52
+ const rowTransform = options.standardization || false;
53
+ const features = [];
54
+ meta_1.featureEach(fc, (feature) => {
58
55
  features.push(centroid_1.default(feature));
59
56
  });
60
57
  // computing the distance between the features
61
- var weights = [];
62
- for (var i = 0; i < features.length; i++) {
58
+ const weights = [];
59
+ for (let i = 0; i < features.length; i++) {
63
60
  weights[i] = [];
64
61
  }
65
- for (var i = 0; i < features.length; i++) {
66
- for (var j = i; j < features.length; j++) {
62
+ for (let i = 0; i < features.length; i++) {
63
+ for (let j = i; j < features.length; j++) {
67
64
  if (i === j) {
68
65
  weights[i][j] = 0;
69
66
  }
70
- var dis = pNormDistance(features[i], features[j], p);
67
+ const dis = pNormDistance(features[i], features[j], p);
71
68
  weights[i][j] = dis;
72
69
  weights[j][i] = dis;
73
70
  }
74
71
  }
75
72
  // binary or distance decay
76
- for (var i = 0; i < features.length; i++) {
77
- for (var j = 0; j < features.length; j++) {
78
- var dis = weights[i][j];
73
+ for (let i = 0; i < features.length; i++) {
74
+ for (let j = 0; j < features.length; j++) {
75
+ const dis = weights[i][j];
79
76
  if (dis === 0) {
80
77
  continue;
81
78
  }
@@ -98,11 +95,11 @@ function distanceWeight(fc, options) {
98
95
  }
99
96
  }
100
97
  if (rowTransform) {
101
- for (var i = 0; i < features.length; i++) {
102
- var rowSum = weights[i].reduce(function (sum, currentVal) {
98
+ for (let i = 0; i < features.length; i++) {
99
+ const rowSum = weights[i].reduce((sum, currentVal) => {
103
100
  return sum + currentVal;
104
101
  }, 0);
105
- for (var j = 0; j < features.length; j++) {
102
+ for (let j = 0; j < features.length; j++) {
106
103
  weights[i][j] = weights[i][j] / rowSum;
107
104
  }
108
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/distance-weight",
3
- "version": "6.4.0",
3
+ "version": "7.0.0-alpha.0",
4
4
  "description": "turf distance-weight module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -15,6 +15,7 @@
15
15
  "type": "git",
16
16
  "url": "git://github.com/Turfjs/turf.git"
17
17
  },
18
+ "funding": "https://opencollective.com/turf",
18
19
  "publishConfig": {
19
20
  "access": "public"
20
21
  },
@@ -57,10 +58,11 @@
57
58
  "write-json-file": "*"
58
59
  },
59
60
  "dependencies": {
60
- "@turf/centroid": "^6.4.0",
61
- "@turf/helpers": "^6.4.0",
62
- "@turf/invariant": "^6.4.0",
63
- "@turf/meta": "^6.4.0"
61
+ "@turf/centroid": "^7.0.0-alpha.0",
62
+ "@turf/helpers": "^7.0.0-alpha.0",
63
+ "@turf/invariant": "^7.0.0-alpha.0",
64
+ "@turf/meta": "^7.0.0-alpha.0",
65
+ "tslib": "^2.3.0"
64
66
  },
65
- "gitHead": "1e62773cfc88c627cca8effcb5c14cfb65a905ac"
67
+ "gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
66
68
  }