@turf/standard-deviational-ellipse
Advanced tools
Comparing version 7.1.0-alpha.7 to 7.1.0-alpha.70
import { Position, Feature, Polygon, FeatureCollection, Point, GeoJsonProperties } from 'geojson'; | ||
/** | ||
* http://turfjs.org/docs/#standarddeviational-ellipse | ||
*/ | ||
declare interface SDEProps { | ||
meanCenterCoordinates: Position; | ||
semiMajorAxis: number; | ||
semiMinorAxis: number; | ||
numberOfFeatures: number; | ||
angle: number; | ||
percentageWithinEllipse: number; | ||
meanCenterCoordinates: Position; | ||
semiMajorAxis: number; | ||
semiMinorAxis: number; | ||
numberOfFeatures: number; | ||
angle: number; | ||
percentageWithinEllipse: number; | ||
} | ||
declare interface StandardDeviationalEllipse extends Feature<Polygon> { | ||
properties: { | ||
standardDeviationalEllipse: SDEProps; | ||
[key: string]: any; | ||
}; | ||
properties: { | ||
standardDeviationalEllipse: SDEProps; | ||
[key: string]: any; | ||
} | null; | ||
} | ||
declare function standardDeviationalEllipse( | ||
points: FeatureCollection<Point>, | ||
options?: { | ||
/** | ||
* Takes a collection of features 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 deviation’s worth (~ 70%) of the | ||
* data. | ||
* | ||
* This module mirrors the functionality of {@link http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-statistics-toolbox/directional-distribution.htm|Directional Distribution} | ||
* in ArcGIS and the {@link http://arken.nmbu.no/~havatv/gis/qgisplugins/SDEllipse/|QGIS Standard Deviational Ellipse Plugin} | ||
* | ||
* **Bibliography** | ||
* | ||
* • Robert S. Yuill, “The Standard Deviational Ellipse; An Updated Tool for | ||
* Spatial Description,” _Geografiska Annaler_ 53, no. 1 (1971): 28–39, | ||
* doi:{@link https://doi.org/10.2307/490885|10.2307/490885}. | ||
* | ||
* • Paul Hanly Furfey, “A Note on Lefever’s “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 | ||
* | ||
* const bbox = [-74, 40.72, -73.98, 40.74]; | ||
* const points = turf.randomPoint(400, {bbox: bbox}); | ||
* const sdEllipse = turf.standardDeviationalEllipse(points); | ||
* | ||
* //addToMap | ||
* const addToMap = [points, sdEllipse]; | ||
* | ||
*/ | ||
declare function standardDeviationalEllipse(points: FeatureCollection<Point>, options?: { | ||
properties?: GeoJsonProperties; | ||
weight?: string; | ||
steps?: number; | ||
} | ||
): StandardDeviationalEllipse; | ||
}): StandardDeviationalEllipse; | ||
export { type SDEProps, type StandardDeviationalEllipse, standardDeviationalEllipse as default, standardDeviationalEllipse }; |
@@ -1,2 +0,2 @@ | ||
// index.js | ||
// index.ts | ||
import { coordAll, featureEach } from "@turf/meta"; | ||
@@ -9,8 +9,9 @@ import { getCoords } from "@turf/invariant"; | ||
function standardDeviationalEllipse(points, options) { | ||
var _a; | ||
options = options || {}; | ||
if (!isObject(options)) | ||
throw new Error("options is invalid"); | ||
var steps = options.steps || 64; | ||
var weightTerm = options.weight; | ||
var properties = options.properties || {}; | ||
const steps = options.steps || 64; | ||
const weightTerm = options.weight; | ||
const properties = options.properties || {}; | ||
if (!isNumber(steps)) | ||
@@ -20,10 +21,11 @@ throw new Error("steps must be a number"); | ||
throw new Error("properties must be a number"); | ||
var numberOfFeatures = coordAll(points).length; | ||
var meanCenter = centerMean(points, { weight: weightTerm }); | ||
var xDeviationSquaredSum = 0; | ||
var yDeviationSquaredSum = 0; | ||
var xyDeviationSum = 0; | ||
const numberOfFeatures = coordAll(points).length; | ||
const meanCenter = centerMean(points, { weight: weightTerm }); | ||
let xDeviationSquaredSum = 0; | ||
let yDeviationSquaredSum = 0; | ||
let xyDeviationSum = 0; | ||
featureEach(points, function(point) { | ||
var weight = point.properties[weightTerm] || 1; | ||
var deviation = getDeviations(getCoords(point), getCoords(meanCenter)); | ||
var _a2; | ||
const weight = weightTerm ? ((_a2 = point.properties) == null ? void 0 : _a2[weightTerm]) || 1 : 1; | ||
const deviation = getDeviations(getCoords(point), getCoords(meanCenter)); | ||
xDeviationSquaredSum += Math.pow(deviation.x, 2) * weight; | ||
@@ -33,13 +35,14 @@ yDeviationSquaredSum += Math.pow(deviation.y, 2) * 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; | ||
var sigmaXsum = 0; | ||
var sigmaYsum = 0; | ||
var weightsum = 0; | ||
const bigA = xDeviationSquaredSum - yDeviationSquaredSum; | ||
const bigB = Math.sqrt(Math.pow(bigA, 2) + 4 * Math.pow(xyDeviationSum, 2)); | ||
const bigC = 2 * xyDeviationSum; | ||
const theta = Math.atan((bigA + bigB) / bigC); | ||
const thetaDeg = theta * 180 / Math.PI; | ||
let sigmaXsum = 0; | ||
let sigmaYsum = 0; | ||
let weightsum = 0; | ||
featureEach(points, function(point) { | ||
var weight = point.properties[weightTerm] || 1; | ||
var deviation = getDeviations(getCoords(point), getCoords(meanCenter)); | ||
var _a2; | ||
const weight = weightTerm ? ((_a2 = point.properties) == null ? void 0 : _a2[weightTerm]) || 1 : 1; | ||
const deviation = getDeviations(getCoords(point), getCoords(meanCenter)); | ||
sigmaXsum += Math.pow( | ||
@@ -55,5 +58,5 @@ deviation.x * Math.cos(theta) - deviation.y * Math.sin(theta), | ||
}); | ||
var sigmaX = Math.sqrt(2 * sigmaXsum / weightsum); | ||
var sigmaY = Math.sqrt(2 * sigmaYsum / weightsum); | ||
var theEllipse = ellipse(meanCenter, sigmaX, sigmaY, { | ||
const sigmaX = Math.sqrt(2 * sigmaXsum / weightsum); | ||
const sigmaY = Math.sqrt(2 * sigmaYsum / weightsum); | ||
const theEllipse = ellipse(meanCenter, sigmaX, sigmaY, { | ||
units: "degrees", | ||
@@ -64,7 +67,7 @@ angle: thetaDeg, | ||
}); | ||
var pointsWithinEllipse = pointsWithinPolygon( | ||
const pointsWithinEllipse = pointsWithinPolygon( | ||
points, | ||
featureCollection([theEllipse]) | ||
); | ||
var standardDeviationalEllipseProperties = { | ||
const standardDeviationalEllipseProperties = { | ||
meanCenterCoordinates: getCoords(meanCenter), | ||
@@ -77,2 +80,3 @@ semiMajorAxis: sigmaX, | ||
}; | ||
theEllipse.properties = (_a = theEllipse.properties) != null ? _a : {}; | ||
theEllipse.properties.standardDeviationalEllipse = standardDeviationalEllipseProperties; | ||
@@ -79,0 +83,0 @@ return theEllipse; |
{ | ||
"name": "@turf/standard-deviational-ellipse", | ||
"version": "7.1.0-alpha.7+0ce6ecca0", | ||
"version": "7.1.0-alpha.70+948cdafaf", | ||
"description": "turf standard-deviational-ellipse module", | ||
@@ -58,4 +58,4 @@ "author": "Turf Authors", | ||
"devDependencies": { | ||
"@turf/random": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/truncate": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/random": "^7.1.0-alpha.70+948cdafaf", | ||
"@turf/truncate": "^7.1.0-alpha.70+948cdafaf", | ||
"@types/benchmark": "^2.1.5", | ||
@@ -69,13 +69,16 @@ "@types/tape": "^4.2.32", | ||
"tsx": "^4.6.2", | ||
"typescript": "^5.2.2", | ||
"write-json-file": "^5.0.0" | ||
}, | ||
"dependencies": { | ||
"@turf/center-mean": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/ellipse": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/invariant": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/meta": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/points-within-polygon": "^7.1.0-alpha.7+0ce6ecca0" | ||
"@turf/center-mean": "^7.1.0-alpha.70+948cdafaf", | ||
"@turf/ellipse": "^7.1.0-alpha.70+948cdafaf", | ||
"@turf/helpers": "^7.1.0-alpha.70+948cdafaf", | ||
"@turf/invariant": "^7.1.0-alpha.70+948cdafaf", | ||
"@turf/meta": "^7.1.0-alpha.70+948cdafaf", | ||
"@turf/points-within-polygon": "^7.1.0-alpha.70+948cdafaf", | ||
"@types/geojson": "^7946.0.10", | ||
"tslib": "^2.6.2" | ||
}, | ||
"gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea" | ||
"gitHead": "948cdafaf70606d2e27fcc79973fa48ee1182067" | ||
} |
@@ -7,10 +7,10 @@ # @turf/standard-deviational-ellipse | ||
Takes a [FeatureCollection][1] and returns a standard deviational ellipse, | ||
Takes a collection of features 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 deviation’s worth (~ 70%) of the | ||
an ellipse that contains about one standard deviation’s worth (\~ 70%) of the | ||
data. | ||
This module mirrors the functionality of [Directional Distribution][2] | ||
in ArcGIS and the [QGIS Standard Deviational Ellipse Plugin][3] | ||
This module mirrors the functionality of [Directional Distribution][1] | ||
in ArcGIS and the [QGIS Standard Deviational Ellipse Plugin][2] | ||
@@ -21,16 +21,16 @@ **Bibliography** | ||
Spatial Description,” *Geografiska Annaler* 53, no. 1 (1971): 28–39, | ||
doi:{@link [https://doi.org/10.2307/490885|10.2307/490885}][4]. | ||
doi:{@link [https://doi.org/10.2307/490885|10.2307/490885}][3]. | ||
• Paul Hanly Furfey, “A Note on Lefever’s “Standard Deviational Ellipse,” | ||
*American Journal of Sociology* 33, no. 1 (1927): 94—98, | ||
doi:{@link [https://doi.org/10.1086/214336|10.1086/214336}][5]. | ||
doi:{@link [https://doi.org/10.1086/214336|10.1086/214336}][4]. | ||
### Parameters | ||
* `points` **[FeatureCollection][6]<[Point][7]>** GeoJSON points | ||
* `options` **[Object][8]** Optional parameters (optional, default `{}`) | ||
* `points` **[FeatureCollection][5]<[Point][6]>** GeoJSON points | ||
* `options` **[Object][7]** 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 `{}`) | ||
* `options.weight` **[string][8]?** the property name used to weight the center | ||
* `options.steps` **[number][9]** number of steps for the polygon (optional, default `64`) | ||
* `options.properties` **[Object][7]** properties to pass to the resulting ellipse (optional, default `{}`) | ||
@@ -40,36 +40,34 @@ ### Examples | ||
```javascript | ||
var bbox = [-74, 40.72, -73.98, 40.74]; | ||
var points = turf.randomPoint(400, {bbox: bbox}); | ||
var sdEllipse = turf.standardDeviationalEllipse(points); | ||
const bbox = [-74, 40.72, -73.98, 40.74]; | ||
const points = turf.randomPoint(400, {bbox: bbox}); | ||
const sdEllipse = turf.standardDeviationalEllipse(points); | ||
//addToMap | ||
var addToMap = [points, sdEllipse]; | ||
const addToMap = [points, sdEllipse]; | ||
``` | ||
Returns **[Feature][11]<[Polygon][12]>** an elliptical Polygon that includes approximately 1 SD of the dataset within it. | ||
Returns **[Feature][10]<[Polygon][11]>** an elliptical Polygon that includes approximately 1 SD of the dataset within it. | ||
[1]: https://tools.ietf.org/html/rfc7946#section-3.3 | ||
[1]: http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-statistics-toolbox/directional-distribution.htm | ||
[2]: http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-statistics-toolbox/directional-distribution.htm | ||
[2]: http://arken.nmbu.no/~havatv/gis/qgisplugins/SDEllipse/ | ||
[3]: http://arken.nmbu.no/~havatv/gis/qgisplugins/SDEllipse/ | ||
[3]: https://doi.org/10.2307/490885|10.2307/490885} | ||
[4]: https://doi.org/10.2307/490885|10.2307/490885} | ||
[4]: https://doi.org/10.1086/214336|10.1086/214336} | ||
[5]: https://doi.org/10.1086/214336|10.1086/214336} | ||
[5]: https://tools.ietf.org/html/rfc7946#section-3.3 | ||
[6]: https://tools.ietf.org/html/rfc7946#section-3.3 | ||
[6]: https://tools.ietf.org/html/rfc7946#section-3.1.2 | ||
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.2 | ||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object | ||
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object | ||
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String | ||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String | ||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number | ||
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number | ||
[10]: https://tools.ietf.org/html/rfc7946#section-3.2 | ||
[11]: https://tools.ietf.org/html/rfc7946#section-3.2 | ||
[11]: https://tools.ietf.org/html/rfc7946#section-3.1.6 | ||
[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 of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. --> | ||
@@ -76,0 +74,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
37841
234
8
12
89