@turf/nearest-neighbor-analysis
Advanced tools
Comparing version 6.5.0 to 7.0.0-alpha.0
@@ -63,13 +63,13 @@ import area from "@turf/area"; | ||
options = options || {}; | ||
var studyArea = options.studyArea || bboxPolygon(bbox(dataset)); | ||
var properties = options.properties || {}; | ||
var units = options.units || "kilometers"; | ||
var features = []; | ||
featureEach(dataset, function (feature) { | ||
const studyArea = options.studyArea || bboxPolygon(bbox(dataset)); | ||
const properties = options.properties || {}; | ||
const units = options.units || "kilometers"; | ||
const features = []; | ||
featureEach(dataset, (feature) => { | ||
features.push(centroid(feature)); | ||
}); | ||
var n = features.length; | ||
var observedMeanDistance = features | ||
.map(function (feature, index) { | ||
var otherFeatures = featureCollection(features.filter(function (f, i) { | ||
const n = features.length; | ||
const observedMeanDistance = features | ||
.map((feature, index) => { | ||
const otherFeatures = featureCollection(features.filter((f, i) => { | ||
return i !== index; | ||
@@ -79,10 +79,10 @@ })); | ||
// see https://stackoverflow.com/a/40350534/1979085 | ||
return distance(feature, nearestPoint(feature, otherFeatures).geometry.coordinates, { units: units }); | ||
return distance(feature, nearestPoint(feature, otherFeatures).geometry.coordinates, { units }); | ||
}) | ||
.reduce(function (sum, value) { | ||
.reduce((sum, value) => { | ||
return sum + value; | ||
}, 0) / n; | ||
var populationDensity = n / convertArea(area(studyArea), "meters", units); | ||
var expectedMeanDistance = 1 / (2 * Math.sqrt(populationDensity)); | ||
var variance = 0.26136 / Math.sqrt(n * populationDensity); | ||
const populationDensity = n / convertArea(area(studyArea), "meters", units); | ||
const expectedMeanDistance = 1 / (2 * Math.sqrt(populationDensity)); | ||
const variance = 0.26136 / Math.sqrt(n * populationDensity); | ||
properties.nearestNeighborAnalysis = { | ||
@@ -89,0 +89,0 @@ units: units, |
@@ -1,2 +0,3 @@ | ||
import { FeatureCollection, Feature, Polygon, Units, Properties } from "@turf/helpers"; | ||
import { FeatureCollection, Feature, Polygon, GeoJsonProperties } from "geojson"; | ||
import { Units } from "@turf/helpers"; | ||
export interface NearestNeighborStatistics { | ||
@@ -70,4 +71,4 @@ units: Units; | ||
units?: Units; | ||
properties?: Properties; | ||
properties?: GeoJsonProperties; | ||
}): NearestNeighborStudyArea; | ||
export default nearestNeighborAnalysis; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var area_1 = __importDefault(require("@turf/area")); | ||
var bbox_1 = __importDefault(require("@turf/bbox")); | ||
var bbox_polygon_1 = __importDefault(require("@turf/bbox-polygon")); | ||
var centroid_1 = __importDefault(require("@turf/centroid")); | ||
var distance_1 = __importDefault(require("@turf/distance")); | ||
var nearest_point_1 = __importDefault(require("@turf/nearest-point")); | ||
var meta_1 = require("@turf/meta"); | ||
var helpers_1 = require("@turf/helpers"); | ||
const tslib_1 = require("tslib"); | ||
const area_1 = tslib_1.__importDefault(require("@turf/area")); | ||
const bbox_1 = tslib_1.__importDefault(require("@turf/bbox")); | ||
const bbox_polygon_1 = tslib_1.__importDefault(require("@turf/bbox-polygon")); | ||
const centroid_1 = tslib_1.__importDefault(require("@turf/centroid")); | ||
const distance_1 = tslib_1.__importDefault(require("@turf/distance")); | ||
const nearest_point_1 = tslib_1.__importDefault(require("@turf/nearest-point")); | ||
const meta_1 = require("@turf/meta"); | ||
const helpers_1 = require("@turf/helpers"); | ||
/** | ||
@@ -68,13 +66,13 @@ * Nearest Neighbor Analysis calculates an index based the average distances | ||
options = options || {}; | ||
var studyArea = options.studyArea || bbox_polygon_1.default(bbox_1.default(dataset)); | ||
var properties = options.properties || {}; | ||
var units = options.units || "kilometers"; | ||
var features = []; | ||
meta_1.featureEach(dataset, function (feature) { | ||
const studyArea = options.studyArea || bbox_polygon_1.default(bbox_1.default(dataset)); | ||
const properties = options.properties || {}; | ||
const units = options.units || "kilometers"; | ||
const features = []; | ||
meta_1.featureEach(dataset, (feature) => { | ||
features.push(centroid_1.default(feature)); | ||
}); | ||
var n = features.length; | ||
var observedMeanDistance = features | ||
.map(function (feature, index) { | ||
var otherFeatures = helpers_1.featureCollection(features.filter(function (f, i) { | ||
const n = features.length; | ||
const observedMeanDistance = features | ||
.map((feature, index) => { | ||
const otherFeatures = helpers_1.featureCollection(features.filter((f, i) => { | ||
return i !== index; | ||
@@ -84,10 +82,10 @@ })); | ||
// see https://stackoverflow.com/a/40350534/1979085 | ||
return distance_1.default(feature, nearest_point_1.default(feature, otherFeatures).geometry.coordinates, { units: units }); | ||
return distance_1.default(feature, nearest_point_1.default(feature, otherFeatures).geometry.coordinates, { units }); | ||
}) | ||
.reduce(function (sum, value) { | ||
.reduce((sum, value) => { | ||
return sum + value; | ||
}, 0) / n; | ||
var populationDensity = n / helpers_1.convertArea(area_1.default(studyArea), "meters", units); | ||
var expectedMeanDistance = 1 / (2 * Math.sqrt(populationDensity)); | ||
var variance = 0.26136 / Math.sqrt(n * populationDensity); | ||
const populationDensity = n / helpers_1.convertArea(area_1.default(studyArea), "meters", units); | ||
const expectedMeanDistance = 1 / (2 * Math.sqrt(populationDensity)); | ||
const variance = 0.26136 / Math.sqrt(n * populationDensity); | ||
properties.nearestNeighborAnalysis = { | ||
@@ -94,0 +92,0 @@ units: units, |
{ | ||
"name": "@turf/nearest-neighbor-analysis", | ||
"version": "6.5.0", | ||
"version": "7.0.0-alpha.0", | ||
"description": "turf nearest-neighbor-analysis module", | ||
@@ -50,3 +50,3 @@ "author": "Turf Authors", | ||
"devDependencies": { | ||
"@turf/truncate": "^6.5.0", | ||
"@turf/truncate": "^7.0.0-alpha.0", | ||
"@types/tape": "*", | ||
@@ -63,12 +63,13 @@ "benchmark": "*", | ||
"dependencies": { | ||
"@turf/area": "^6.5.0", | ||
"@turf/bbox": "^6.5.0", | ||
"@turf/bbox-polygon": "^6.5.0", | ||
"@turf/centroid": "^6.5.0", | ||
"@turf/distance": "^6.5.0", | ||
"@turf/helpers": "^6.5.0", | ||
"@turf/meta": "^6.5.0", | ||
"@turf/nearest-point": "^6.5.0" | ||
"@turf/area": "^7.0.0-alpha.0", | ||
"@turf/bbox": "^7.0.0-alpha.0", | ||
"@turf/bbox-polygon": "^7.0.0-alpha.0", | ||
"@turf/centroid": "^7.0.0-alpha.0", | ||
"@turf/distance": "^7.0.0-alpha.0", | ||
"@turf/helpers": "^7.0.0-alpha.0", | ||
"@turf/meta": "^7.0.0-alpha.0", | ||
"@turf/nearest-point": "^7.0.0-alpha.0", | ||
"tslib": "^2.3.0" | ||
}, | ||
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e" | ||
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189" | ||
} |
@@ -11,10 +11,10 @@ # @turf/nearest-neighbor-analysis | ||
It returns a [Feature<Polygon>][1] of the study area, with the results of | ||
It returns a [Feature\<Polygon>][1] of the study area, with the results of | ||
the analysis attached as part of of the `nearestNeighborAnalysis` property | ||
of the study area's `properties`. The attached | ||
[_z_-score][2] indicates how many | ||
[*z*-score][2] indicates how many | ||
standard deviations above or below the expected mean distance the data's | ||
observed mean distance is. The more negative, the more clustered. The more | ||
positive, the more evenly dispersed. A _z_-score between -2 and 2 indicates | ||
a seemingly random distribution. That is, within _p_ of less than 0.05, the | ||
positive, the more evenly dispersed. A *z*-score between -2 and 2 indicates | ||
a seemingly random distribution. That is, within *p* of less than 0.05, the | ||
distribution appears statistically significantly neither clustered nor | ||
@@ -25,29 +25,33 @@ dispersed. | ||
- Though the analysis will work on any [FeatureCollection][3] type, it | ||
works best with [Point][4] collections. | ||
* Though the analysis will work on any [FeatureCollection][3] type, it | ||
- This analysis is _very_ sensitive to the study area provided. If no [Feature<Polygon>][1] is passed as the study area, the function draws a box | ||
around the data, which may distort the findings. This analysis works best | ||
with a bounded area of interest within with the data is either clustered, | ||
dispersed, or randomly distributed. For example, a city's subway stops may | ||
look extremely clustered if the study area is an entire state. On the other | ||
hand, they may look rather evenly dispersed if the study area is limited to | ||
the city's downtown. | ||
works best with [Point][4] collections. | ||
* This analysis is *very* sensitive to the study area provided. | ||
If no [Feature\<Polygon>][1] is passed as the study area, the function draws a box | ||
around the data, which may distort the findings. This analysis works best | ||
with a bounded area of interest within with the data is either clustered, | ||
dispersed, or randomly distributed. For example, a city's subway stops may | ||
look extremely clustered if the study area is an entire state. On the other | ||
hand, they may look rather evenly dispersed if the study area is limited to | ||
the city's downtown. | ||
**Bibliography** | ||
Philip J. Clark and Francis C. Evans, “Distance to Nearest Neighbor as a | ||
Measure of Spatial Relationships in Populations,” _Ecology_ 35, no. 4 | ||
Measure of Spatial Relationships in Populations,” *Ecology* 35, no. 4 | ||
(1954): 445–453, doi:[10.2307/1931034][5]. | ||
**Parameters** | ||
### Parameters | ||
- `dataset` **[FeatureCollection][6]<any>** FeatureCollection (pref. of points) to study | ||
- `options` **[Object][7]** Optional parameters (optional, default `{}`) | ||
- `options.studyArea` **[Feature][8]<[Polygon][9]>?** polygon representing the study area | ||
- `options.units` **[string][10]** unit of measurement for distances and, squared, area. (optional, default `'kilometers'`) | ||
- `options.properties` **[Object][7]** properties (optional, default `{}`) | ||
* `dataset` **[FeatureCollection][6]\<any>** FeatureCollection (pref. of points) to study | ||
* `options` **[Object][7]** Optional parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.studyArea` **[Feature][8]<[Polygon][9]>?** polygon representing the study area | ||
* `options.units` **[string][10]** unit of measurement for distances and, squared, area. (optional, default `'kilometers'`) | ||
* `options.properties` **[Object][7]** properties (optional, default `{}`) | ||
### Examples | ||
```javascript | ||
@@ -62,3 +66,3 @@ var bbox = [-65, 40, -63, 42]; | ||
Returns **[Feature][8]<[Polygon][9]>** A polygon of the study area or an approximation of one. | ||
Returns **[Feature][8]<[Polygon][9]>** A polygon of the study area or an approximation of one. | ||
@@ -65,0 +69,0 @@ [1]: Feature<Polygon> |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
20076
110
9
272
1
+ Addedtslib@^2.3.0
+ Added@turf/area@7.1.0(transitive)
+ Added@turf/bbox@7.1.0(transitive)
+ Added@turf/bbox-polygon@7.1.0(transitive)
+ Added@turf/centroid@7.1.0(transitive)
+ Added@turf/clone@7.1.0(transitive)
+ Added@turf/distance@7.1.0(transitive)
+ Added@turf/helpers@7.1.0(transitive)
+ Added@turf/invariant@7.1.0(transitive)
+ Added@turf/meta@7.1.0(transitive)
+ Added@turf/nearest-point@7.1.0(transitive)
+ Added@types/geojson@7946.0.15(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@turf/area@6.5.0(transitive)
- Removed@turf/bbox@6.5.0(transitive)
- Removed@turf/bbox-polygon@6.5.0(transitive)
- Removed@turf/centroid@6.5.0(transitive)
- Removed@turf/clone@6.5.0(transitive)
- Removed@turf/distance@6.5.0(transitive)
- Removed@turf/helpers@6.5.0(transitive)
- Removed@turf/invariant@6.5.0(transitive)
- Removed@turf/meta@6.5.0(transitive)
- Removed@turf/nearest-point@6.5.0(transitive)
Updated@turf/area@^7.0.0-alpha.0
Updated@turf/bbox@^7.0.0-alpha.0
Updated@turf/helpers@^7.0.0-alpha.0
Updated@turf/meta@^7.0.0-alpha.0