New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@turf/distance-weight

Package Overview
Dependencies
Maintainers
7
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/distance-weight - npm Package Compare versions

Comparing version 6.5.0 to 7.0.0-alpha.0

47

dist/es/index.js

@@ -10,8 +10,7 @@ import centroid from "@turf/centroid";

*/
export function pNormDistance(feature1, feature2, p) {
if (p === void 0) { p = 2; }
var coordinate1 = getCoord(feature1);
var coordinate2 = getCoord(feature2);
var xDiff = coordinate1[0] - coordinate2[0];
var yDiff = coordinate1[1] - coordinate2[1];
export function pNormDistance(feature1, feature2, p = 2) {
const coordinate1 = getCoord(feature1);
const coordinate2 = getCoord(feature2);
const xDiff = coordinate1[0] - coordinate2[0];
const yDiff = coordinate1[1] - coordinate2[1];
if (p === 1) {

@@ -46,22 +45,22 @@ return Math.abs(xDiff) + Math.abs(yDiff);

options = options || {};
var threshold = options.threshold || 10000;
var p = options.p || 2;
var binary = options.binary || false;
var alpha = options.alpha || -1;
var rowTransform = options.standardization || false;
var features = [];
featureEach(fc, function (feature) {
const threshold = options.threshold || 10000;
const p = options.p || 2;
const binary = options.binary || false;
const alpha = options.alpha || -1;
const rowTransform = options.standardization || false;
const features = [];
featureEach(fc, (feature) => {
features.push(centroid(feature));
});
// computing the distance between the features
var weights = [];
for (var i = 0; i < features.length; i++) {
const weights = [];
for (let i = 0; i < features.length; i++) {
weights[i] = [];
}
for (var i = 0; i < features.length; i++) {
for (var j = i; j < features.length; j++) {
for (let i = 0; i < features.length; i++) {
for (let j = i; j < features.length; j++) {
if (i === j) {
weights[i][j] = 0;
}
var dis = pNormDistance(features[i], features[j], p);
const dis = pNormDistance(features[i], features[j], p);
weights[i][j] = dis;

@@ -72,5 +71,5 @@ weights[j][i] = dis;

// binary or distance decay
for (var i = 0; i < features.length; i++) {
for (var j = 0; j < features.length; j++) {
var dis = weights[i][j];
for (let i = 0; i < features.length; i++) {
for (let j = 0; j < features.length; j++) {
const dis = weights[i][j];
if (dis === 0) {

@@ -98,7 +97,7 @@ continue;

if (rowTransform) {
for (var i = 0; i < features.length; i++) {
var rowSum = weights[i].reduce(function (sum, currentVal) {
for (let i = 0; i < features.length; i++) {
const rowSum = weights[i].reduce((sum, currentVal) => {
return sum + currentVal;
}, 0);
for (var j = 0; j < features.length; j++) {
for (let j = 0; j < features.length; j++) {
weights[i][j] = weights[i][j] / rowSum;

@@ -105,0 +104,0 @@ }

@@ -1,2 +0,2 @@

import { Feature, FeatureCollection, Point } from "@turf/helpers";
import { Feature, FeatureCollection, Point } from "geojson";
/**

@@ -3,0 +3,0 @@ * calcualte the Minkowski p-norm distance between two features.

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var centroid_1 = __importDefault(require("@turf/centroid"));
var invariant_1 = require("@turf/invariant");
var meta_1 = require("@turf/meta");
const tslib_1 = require("tslib");
const centroid_1 = tslib_1.__importDefault(require("@turf/centroid"));
const invariant_1 = require("@turf/invariant");
const meta_1 = require("@turf/meta");
/**

@@ -15,8 +13,7 @@ * calcualte the Minkowski p-norm distance between two features.

*/
function pNormDistance(feature1, feature2, p) {
if (p === void 0) { p = 2; }
var coordinate1 = invariant_1.getCoord(feature1);
var coordinate2 = invariant_1.getCoord(feature2);
var xDiff = coordinate1[0] - coordinate2[0];
var yDiff = coordinate1[1] - coordinate2[1];
function pNormDistance(feature1, feature2, p = 2) {
const coordinate1 = invariant_1.getCoord(feature1);
const coordinate2 = invariant_1.getCoord(feature2);
const xDiff = coordinate1[0] - coordinate2[0];
const yDiff = coordinate1[1] - coordinate2[1];
if (p === 1) {

@@ -52,22 +49,22 @@ return Math.abs(xDiff) + Math.abs(yDiff);

options = options || {};
var threshold = options.threshold || 10000;
var p = options.p || 2;
var binary = options.binary || false;
var alpha = options.alpha || -1;
var rowTransform = options.standardization || false;
var features = [];
meta_1.featureEach(fc, function (feature) {
const threshold = options.threshold || 10000;
const p = options.p || 2;
const binary = options.binary || false;
const alpha = options.alpha || -1;
const rowTransform = options.standardization || false;
const features = [];
meta_1.featureEach(fc, (feature) => {
features.push(centroid_1.default(feature));
});
// computing the distance between the features
var weights = [];
for (var i = 0; i < features.length; i++) {
const weights = [];
for (let i = 0; i < features.length; i++) {
weights[i] = [];
}
for (var i = 0; i < features.length; i++) {
for (var j = i; j < features.length; j++) {
for (let i = 0; i < features.length; i++) {
for (let j = i; j < features.length; j++) {
if (i === j) {
weights[i][j] = 0;
}
var dis = pNormDistance(features[i], features[j], p);
const dis = pNormDistance(features[i], features[j], p);
weights[i][j] = dis;

@@ -78,5 +75,5 @@ weights[j][i] = dis;

// binary or distance decay
for (var i = 0; i < features.length; i++) {
for (var j = 0; j < features.length; j++) {
var dis = weights[i][j];
for (let i = 0; i < features.length; i++) {
for (let j = 0; j < features.length; j++) {
const dis = weights[i][j];
if (dis === 0) {

@@ -104,7 +101,7 @@ continue;

if (rowTransform) {
for (var i = 0; i < features.length; i++) {
var rowSum = weights[i].reduce(function (sum, currentVal) {
for (let i = 0; i < features.length; i++) {
const rowSum = weights[i].reduce((sum, currentVal) => {
return sum + currentVal;
}, 0);
for (var j = 0; j < features.length; j++) {
for (let j = 0; j < features.length; j++) {
weights[i][j] = weights[i][j] / rowSum;

@@ -111,0 +108,0 @@ }

{
"name": "@turf/distance-weight",
"version": "6.5.0",
"version": "7.0.0-alpha.0",
"description": "turf distance-weight module",

@@ -61,8 +61,9 @@ "author": "Turf Authors",

"dependencies": {
"@turf/centroid": "^6.5.0",
"@turf/helpers": "^6.5.0",
"@turf/invariant": "^6.5.0",
"@turf/meta": "^6.5.0"
"@turf/centroid": "^7.0.0-alpha.0",
"@turf/helpers": "^7.0.0-alpha.0",
"@turf/invariant": "^7.0.0-alpha.0",
"@turf/meta": "^7.0.0-alpha.0",
"tslib": "^2.3.0"
},
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
}

@@ -9,25 +9,28 @@ # @turf/distance-weight

**Parameters**
### Parameters
- `feature1` point feature
- `feature2` point feature
- `p` p-norm 1=&lt;p&lt;=infinity 1: Manhattan distance 2: Euclidean distance
* `feature1` **[Feature][1]<[Point][2]>** point feature
* `feature2` **[Feature][1]<[Point][2]>** point feature
* `p` p-norm 1=\<p<=infinity 1: Manhattan distance 2: Euclidean distance (optional, default `2`)
Returns **[number][3]**
## distanceWeight
**Parameters**
### Parameters
- `fc` **[FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3)&lt;any>** FeatureCollection.
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** option object.
- `options.threshold` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** If the distance between neighbor and
* `fc` **[FeatureCollection][4]\<any>** FeatureCollection.
* `options` **[Object][5]?** option object.
* `options.threshold` **[number][3]** If the distance between neighbor and
target features is greater than threshold, the weight of that neighbor is 0. (optional, default `10000`)
- `options.p` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Minkowski p-norm distance parameter.
1: Manhattan distance. 2: Euclidean distance. 1=&lt;p&lt;=infinity. (optional, default `2`)
- `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.
If false, weight=Math.pow(d, alpha). (optional, default `false`)
- `options.alpha` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** distance decay parameter.
* `options.p` **[number][3]** Minkowski p-norm distance parameter.
1: Manhattan distance. 2: Euclidean distance. 1=\<p<=infinity. (optional, default `2`)
* `options.binary` **[boolean][6]** If true, weight=1 if d <= threshold otherwise weight=0.
If false, weight=Math.pow(d, alpha). (optional, default `false`)
* `options.alpha` **[number][3]** distance decay parameter.
A big value means the weight decay quickly as distance increases. (optional, default `-1`)
- `options.standardization` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** row standardization. (optional, default `false`)
* `options.standardization` **[boolean][6]** row standardization. (optional, default `false`)
**Examples**
### Examples

@@ -40,4 +43,18 @@ ```javascript

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.
Returns **[Array][7]<[Array][7]<[number][3]>>** distance weight matrix.
[1]: https://tools.ietf.org/html/rfc7946#section-3.2
[2]: https://tools.ietf.org/html/rfc7946#section-3.1.2
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[4]: https://tools.ietf.org/html/rfc7946#section-3.3
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
<!-- This file is automatically generated. Please don't edit it directly:

@@ -44,0 +61,0 @@ if you find an error, edit the source file (likely index.js), and re-run

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc