all these changes

This commit is contained in:
Jake Kasper
2026-04-09 13:19:47 -05:00
parent e83a51a051
commit 65315f36d1
39102 changed files with 7932979 additions and 567 deletions

View File

@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2017 TurfJS
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,94 @@
# @turf/standard-deviational-ellipse
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
## standardDeviationalEllipse
Takes a [FeatureCollection][1] and returns a standard deviational ellipse,
also known as a “directional distribution.” The standard deviational ellipse
aims to show the direction and the distribution of a dataset by drawing
an ellipse that contains about one standard deviations worth (~ 70%) of the
data.
This module mirrors the functionality of [Directional Distribution][2]
in ArcGIS and the [QGIS Standard Deviational Ellipse Plugin][3]
**Bibliography**
• Robert S. Yuill, “The Standard Deviational Ellipse; An Updated Tool for
Spatial Description,” _Geografiska Annaler_ 53, no. 1 (1971): 2839,
doi:[10.2307/490885][4].
• Paul Hanly Furfey, “A Note on Lefevers “Standard Deviational Ellipse,”
_American Journal of Sociology_ 33, no. 1 (1927): 94—98,
doi:[10.1086/214336][5].
**Parameters**
- `points` **[FeatureCollection][6]&lt;[Point][7]>** GeoJSON points
- `options` **[Object][8]** Optional parameters (optional, default `{}`)
- `options.weight` **[string][9]?** the property name used to weight the center
- `options.steps` **[number][10]** number of steps for the polygon (optional, default `64`)
- `options.properties` **[Object][8]** properties to pass to the resulting ellipse (optional, default `{}`)
**Examples**
```javascript
var bbox = [-74, 40.72, -73.98, 40.74];
var points = turf.randomPoint(400, {bbox: bbox});
var sdEllipse = turf.standardDeviationalEllipse(points);
//addToMap
var addToMap = [points, sdEllipse];
```
Returns **[Feature][11]&lt;[Polygon][12]>** an elliptical Polygon that includes approximately 1 SD of the dataset within it.
[1]: https://tools.ietf.org/html/rfc7946#section-3.3
[2]: http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-statistics-toolbox/directional-distribution.htm
[3]: http://arken.nmbu.no/~havatv/gis/qgisplugins/SDEllipse/
[4]: https://doi.org/10.2307/490885
[5]: https://doi.org/10.1086/214336
[6]: https://tools.ietf.org/html/rfc7946#section-3.3
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.2
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[11]: https://tools.ietf.org/html/rfc7946#section-3.2
[12]: https://tools.ietf.org/html/rfc7946#section-3.1.6
<!-- This file is automatically generated. Please don't edit it directly:
if you find an error, edit the source file (likely index.js), and re-run
./scripts/generate-readmes in the turf project. -->
---
This module is part of the [Turfjs project](http://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.
### Installation
Install this module individually:
```sh
$ npm install @turf/standard-deviational-ellipse
```
Or install the Turf module that includes it as a function:
```sh
$ npm install @turf/turf
```

View File

@@ -0,0 +1,151 @@
import { coordAll, featureEach } from '@turf/meta';
import { getCoords } from '@turf/invariant';
import { isObject, isNumber, featureCollection } from '@turf/helpers';
import centerMean from '@turf/center-mean';
import pointsWithinPolygon from '@turf/points-within-polygon';
import ellipse from '@turf/ellipse';
/**
* Takes a {@link FeatureCollection} and returns a standard deviational ellipse,
* also known as a “directional distribution.” The standard deviational ellipse
* aims to show the direction and the distribution of a dataset by drawing
* an ellipse that contains about one standard deviations worth (~ 70%) of the
* data.
*
* This module mirrors the functionality of [Directional Distribution](http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-statistics-toolbox/directional-distribution.htm)
* in ArcGIS and the [QGIS Standard Deviational Ellipse Plugin](http://arken.nmbu.no/~havatv/gis/qgisplugins/SDEllipse/)
*
* **Bibliography**
*
* • Robert S. Yuill, “The Standard Deviational Ellipse; An Updated Tool for
* Spatial Description,” _Geografiska Annaler_ 53, no. 1 (1971): 2839,
* doi:{@link https://doi.org/10.2307/490885|10.2307/490885}.
*
* • Paul Hanly Furfey, “A Note on Lefevers “Standard Deviational Ellipse,”
* _American Journal of Sociology_ 33, no. 1 (1927): 94—98,
* doi:{@link https://doi.org/10.1086/214336|10.1086/214336}.
*
*
* @name standardDeviationalEllipse
* @param {FeatureCollection<Point>} points GeoJSON points
* @param {Object} [options={}] Optional parameters
* @param {string} [options.weight] the property name used to weight the center
* @param {number} [options.steps=64] number of steps for the polygon
* @param {Object} [options.properties={}] properties to pass to the resulting ellipse
* @returns {Feature<Polygon>} an elliptical Polygon that includes approximately 1 SD of the dataset within it.
* @example
*
* var bbox = [-74, 40.72, -73.98, 40.74];
* var points = turf.randomPoint(400, {bbox: bbox});
* var sdEllipse = turf.standardDeviationalEllipse(points);
*
* //addToMap
* var addToMap = [points, sdEllipse];
*
*/
function standardDeviationalEllipse(points, options) {
// Optional params
options = options || {};
if (!isObject(options)) throw new Error("options is invalid");
var steps = options.steps || 64;
var weightTerm = options.weight;
var properties = options.properties || {};
// Validation:
if (!isNumber(steps)) throw new Error("steps must be a number");
if (!isObject(properties)) throw new Error("properties must be a number");
// Calculate mean center & number of features:
var numberOfFeatures = coordAll(points).length;
var meanCenter = centerMean(points, { weight: weightTerm });
// Calculate angle of rotation:
// [X, Y] = mean center of all [x, y].
// theta = arctan( (A + B) / C )
// A = sum((x - X)^2) - sum((y - Y)^2)
// B = sqrt(A^2 + 4(sum((x - X)(y - Y))^2))
// C = 2(sum((x - X)(y - Y)))
var xDeviationSquaredSum = 0;
var yDeviationSquaredSum = 0;
var xyDeviationSum = 0;
featureEach(points, function (point) {
var weight = point.properties[weightTerm] || 1;
var deviation = getDeviations(getCoords(point), getCoords(meanCenter));
xDeviationSquaredSum += Math.pow(deviation.x, 2) * weight;
yDeviationSquaredSum += Math.pow(deviation.y, 2) * weight;
xyDeviationSum += deviation.x * deviation.y * weight;
});
var bigA = xDeviationSquaredSum - yDeviationSquaredSum;
var bigB = Math.sqrt(Math.pow(bigA, 2) + 4 * Math.pow(xyDeviationSum, 2));
var bigC = 2 * xyDeviationSum;
var theta = Math.atan((bigA + bigB) / bigC);
var thetaDeg = (theta * 180) / Math.PI;
// Calculate axes:
// sigmaX = sqrt((1 / n - 2) * sum((((x - X) * cos(theta)) - ((y - Y) * sin(theta)))^2))
// sigmaY = sqrt((1 / n - 2) * sum((((x - X) * sin(theta)) - ((y - Y) * cos(theta)))^2))
var sigmaXsum = 0;
var sigmaYsum = 0;
var weightsum = 0;
featureEach(points, function (point) {
var weight = point.properties[weightTerm] || 1;
var deviation = getDeviations(getCoords(point), getCoords(meanCenter));
sigmaXsum +=
Math.pow(
deviation.x * Math.cos(theta) - deviation.y * Math.sin(theta),
2
) * weight;
sigmaYsum +=
Math.pow(
deviation.x * Math.sin(theta) + deviation.y * Math.cos(theta),
2
) * weight;
weightsum += weight;
});
var sigmaX = Math.sqrt((2 * sigmaXsum) / weightsum);
var sigmaY = Math.sqrt((2 * sigmaYsum) / weightsum);
var theEllipse = ellipse(meanCenter, sigmaX, sigmaY, {
units: "degrees",
angle: thetaDeg,
steps: steps,
properties: properties,
});
var pointsWithinEllipse = pointsWithinPolygon(
points,
featureCollection([theEllipse])
);
var standardDeviationalEllipseProperties = {
meanCenterCoordinates: getCoords(meanCenter),
semiMajorAxis: sigmaX,
semiMinorAxis: sigmaY,
numberOfFeatures: numberOfFeatures,
angle: thetaDeg,
percentageWithinEllipse:
(100 * coordAll(pointsWithinEllipse).length) / numberOfFeatures,
};
theEllipse.properties.standardDeviationalEllipse = standardDeviationalEllipseProperties;
return theEllipse;
}
/**
* Get x_i - X and y_i - Y
*
* @private
* @param {Array} coordinates Array of [x_i, y_i]
* @param {Array} center Array of [X, Y]
* @returns {Object} { x: n, y: m }
*/
function getDeviations(coordinates, center) {
return {
x: coordinates[0] - center[0],
y: coordinates[1] - center[1],
};
}
export default standardDeviationalEllipse;

View File

@@ -0,0 +1 @@
{"type":"module"}

View File

@@ -0,0 +1,160 @@
'use strict';
var meta = require('@turf/meta');
var invariant = require('@turf/invariant');
var helpers = require('@turf/helpers');
var centerMean = require('@turf/center-mean');
var pointsWithinPolygon = require('@turf/points-within-polygon');
var ellipse = require('@turf/ellipse');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var centerMean__default = /*#__PURE__*/_interopDefaultLegacy(centerMean);
var pointsWithinPolygon__default = /*#__PURE__*/_interopDefaultLegacy(pointsWithinPolygon);
var ellipse__default = /*#__PURE__*/_interopDefaultLegacy(ellipse);
/**
* Takes a {@link FeatureCollection} and returns a standard deviational ellipse,
* also known as a “directional distribution.” The standard deviational ellipse
* aims to show the direction and the distribution of a dataset by drawing
* an ellipse that contains about one standard deviations worth (~ 70%) of the
* data.
*
* This module mirrors the functionality of [Directional Distribution](http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-statistics-toolbox/directional-distribution.htm)
* in ArcGIS and the [QGIS Standard Deviational Ellipse Plugin](http://arken.nmbu.no/~havatv/gis/qgisplugins/SDEllipse/)
*
* **Bibliography**
*
* • Robert S. Yuill, “The Standard Deviational Ellipse; An Updated Tool for
* Spatial Description,” _Geografiska Annaler_ 53, no. 1 (1971): 2839,
* doi:{@link https://doi.org/10.2307/490885|10.2307/490885}.
*
* • Paul Hanly Furfey, “A Note on Lefevers “Standard Deviational Ellipse,”
* _American Journal of Sociology_ 33, no. 1 (1927): 94—98,
* doi:{@link https://doi.org/10.1086/214336|10.1086/214336}.
*
*
* @name standardDeviationalEllipse
* @param {FeatureCollection<Point>} points GeoJSON points
* @param {Object} [options={}] Optional parameters
* @param {string} [options.weight] the property name used to weight the center
* @param {number} [options.steps=64] number of steps for the polygon
* @param {Object} [options.properties={}] properties to pass to the resulting ellipse
* @returns {Feature<Polygon>} an elliptical Polygon that includes approximately 1 SD of the dataset within it.
* @example
*
* var bbox = [-74, 40.72, -73.98, 40.74];
* var points = turf.randomPoint(400, {bbox: bbox});
* var sdEllipse = turf.standardDeviationalEllipse(points);
*
* //addToMap
* var addToMap = [points, sdEllipse];
*
*/
function standardDeviationalEllipse(points, options) {
// Optional params
options = options || {};
if (!helpers.isObject(options)) throw new Error("options is invalid");
var steps = options.steps || 64;
var weightTerm = options.weight;
var properties = options.properties || {};
// Validation:
if (!helpers.isNumber(steps)) throw new Error("steps must be a number");
if (!helpers.isObject(properties)) throw new Error("properties must be a number");
// Calculate mean center & number of features:
var numberOfFeatures = meta.coordAll(points).length;
var meanCenter = centerMean__default['default'](points, { weight: weightTerm });
// Calculate angle of rotation:
// [X, Y] = mean center of all [x, y].
// theta = arctan( (A + B) / C )
// A = sum((x - X)^2) - sum((y - Y)^2)
// B = sqrt(A^2 + 4(sum((x - X)(y - Y))^2))
// C = 2(sum((x - X)(y - Y)))
var xDeviationSquaredSum = 0;
var yDeviationSquaredSum = 0;
var xyDeviationSum = 0;
meta.featureEach(points, function (point) {
var weight = point.properties[weightTerm] || 1;
var deviation = getDeviations(invariant.getCoords(point), invariant.getCoords(meanCenter));
xDeviationSquaredSum += Math.pow(deviation.x, 2) * weight;
yDeviationSquaredSum += Math.pow(deviation.y, 2) * weight;
xyDeviationSum += deviation.x * deviation.y * weight;
});
var bigA = xDeviationSquaredSum - yDeviationSquaredSum;
var bigB = Math.sqrt(Math.pow(bigA, 2) + 4 * Math.pow(xyDeviationSum, 2));
var bigC = 2 * xyDeviationSum;
var theta = Math.atan((bigA + bigB) / bigC);
var thetaDeg = (theta * 180) / Math.PI;
// Calculate axes:
// sigmaX = sqrt((1 / n - 2) * sum((((x - X) * cos(theta)) - ((y - Y) * sin(theta)))^2))
// sigmaY = sqrt((1 / n - 2) * sum((((x - X) * sin(theta)) - ((y - Y) * cos(theta)))^2))
var sigmaXsum = 0;
var sigmaYsum = 0;
var weightsum = 0;
meta.featureEach(points, function (point) {
var weight = point.properties[weightTerm] || 1;
var deviation = getDeviations(invariant.getCoords(point), invariant.getCoords(meanCenter));
sigmaXsum +=
Math.pow(
deviation.x * Math.cos(theta) - deviation.y * Math.sin(theta),
2
) * weight;
sigmaYsum +=
Math.pow(
deviation.x * Math.sin(theta) + deviation.y * Math.cos(theta),
2
) * weight;
weightsum += weight;
});
var sigmaX = Math.sqrt((2 * sigmaXsum) / weightsum);
var sigmaY = Math.sqrt((2 * sigmaYsum) / weightsum);
var theEllipse = ellipse__default['default'](meanCenter, sigmaX, sigmaY, {
units: "degrees",
angle: thetaDeg,
steps: steps,
properties: properties,
});
var pointsWithinEllipse = pointsWithinPolygon__default['default'](
points,
helpers.featureCollection([theEllipse])
);
var standardDeviationalEllipseProperties = {
meanCenterCoordinates: invariant.getCoords(meanCenter),
semiMajorAxis: sigmaX,
semiMinorAxis: sigmaY,
numberOfFeatures: numberOfFeatures,
angle: thetaDeg,
percentageWithinEllipse:
(100 * meta.coordAll(pointsWithinEllipse).length) / numberOfFeatures,
};
theEllipse.properties.standardDeviationalEllipse = standardDeviationalEllipseProperties;
return theEllipse;
}
/**
* Get x_i - X and y_i - Y
*
* @private
* @param {Array} coordinates Array of [x_i, y_i]
* @param {Array} center Array of [X, Y]
* @returns {Object} { x: n, y: m }
*/
function getDeviations(coordinates, center) {
return {
x: coordinates[0] - center[0],
y: coordinates[1] - center[1],
};
}
module.exports = standardDeviationalEllipse;
module.exports.default = standardDeviationalEllipse;

View File

@@ -0,0 +1,37 @@
import {
FeatureCollection,
Feature,
Position,
Polygon,
Properties,
Point,
} from "@turf/helpers";
/**
* http://turfjs.org/docs/#standarddeviational-ellipse
*/
export interface SDEProps {
meanCenterCoordinates: Position;
semiMajorAxis: number;
semiMinorAxis: number;
numberOfFeatures: number;
angle: number;
percentageWithinEllipse: number;
}
export interface StandardDeviationalEllipse extends Feature<Polygon> {
properties: {
standardDeviationalEllipse: SDEProps;
[key: string]: any;
};
}
export default function (
points: FeatureCollection<Point>,
options?: {
properties?: Properties;
weight?: string;
steps?: number;
}
): StandardDeviationalEllipse;

View File

@@ -0,0 +1,70 @@
{
"name": "@turf/standard-deviational-ellipse",
"version": "6.5.0",
"description": "turf standard-deviational-ellipse module",
"author": "Turf Authors",
"contributors": [
"Moacir P. de Sá Pereira <@muziejus>"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/Turfjs/turf/issues"
},
"homepage": "https://github.com/Turfjs/turf",
"repository": {
"type": "git",
"url": "git://github.com/Turfjs/turf.git"
},
"funding": "https://opencollective.com/turf",
"publishConfig": {
"access": "public"
},
"keywords": [
"turf",
"standard-deviational-ellipse",
"geostatistics",
"directional distribution"
],
"main": "dist/js/index.js",
"module": "dist/es/index.js",
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/es/index.js",
"require": "./dist/js/index.js"
}
},
"types": "index.d.ts",
"sideEffects": false,
"files": [
"dist",
"index.d.ts"
],
"scripts": {
"bench": "node -r esm bench.js",
"build": "rollup -c ../../rollup.config.js && echo '{\"type\":\"module\"}' > dist/es/package.json",
"docs": "node ../../scripts/generate-readmes",
"test": "npm-run-all test:*",
"test:tape": "node -r esm test.js",
"test:types": "tsc --esModuleInterop --noEmit types.ts"
},
"devDependencies": {
"@turf/random": "^6.5.0",
"@turf/truncate": "^6.5.0",
"benchmark": "*",
"load-json-file": "*",
"npm-run-all": "*",
"rollup": "*",
"tape": "*",
"write-json-file": "*"
},
"dependencies": {
"@turf/center-mean": "^6.5.0",
"@turf/ellipse": "^6.5.0",
"@turf/helpers": "^6.5.0",
"@turf/invariant": "^6.5.0",
"@turf/meta": "^6.5.0",
"@turf/points-within-polygon": "^6.5.0"
},
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
}