@turf/nearest-neighbor-analysis 6.5.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
@@ -8,45 +8,49 @@ Nearest Neighbor Analysis calculates an index based the average distances
8
8
  between points in the dataset, thereby providing inference as to whether the
9
9
  data is clustered, dispersed, or randomly distributed within the study area.
10
10
 
11
- It returns a [Feature<Polygon>][1] of the study area, with the results of
11
+ It returns a [Feature\<Polygon>][1] of the study area, with the results of
12
12
  the analysis attached as part of of the `nearestNeighborAnalysis` property
13
13
  of the study area's `properties`. The attached
14
- [_z_-score][2] indicates how many
14
+ [*z*-score][2] indicates how many
15
15
  standard deviations above or below the expected mean distance the data's
16
16
  observed mean distance is. The more negative, the more clustered. The more
17
- positive, the more evenly dispersed. A _z_-score between -2 and 2 indicates
18
- a seemingly random distribution. That is, within _p_ of less than 0.05, the
17
+ positive, the more evenly dispersed. A *z*-score between -2 and 2 indicates
18
+ a seemingly random distribution. That is, within *p* of less than 0.05, the
19
19
  distribution appears statistically significantly neither clustered nor
20
20
  dispersed.
21
21
 
22
22
  **Remarks**
23
23
 
24
- - Though the analysis will work on any [FeatureCollection][3] type, it
25
- works best with [Point][4] collections.
24
+ * Though the analysis will work on any [FeatureCollection][3] type, it
26
25
 
27
- - This analysis is _very_ sensitive to the study area provided. If no [Feature&lt;Polygon>][1] is passed as the study area, the function draws a box
28
- around the data, which may distort the findings. This analysis works best
29
- with a bounded area of interest within with the data is either clustered,
30
- dispersed, or randomly distributed. For example, a city's subway stops may
31
- look extremely clustered if the study area is an entire state. On the other
32
- hand, they may look rather evenly dispersed if the study area is limited to
33
- the city's downtown.
26
+ works best with [Point][4] collections.
27
+
28
+ * This analysis is *very* sensitive to the study area provided.
29
+
30
+ If no [Feature\<Polygon>][1] is passed as the study area, the function draws a box
31
+ around the data, which may distort the findings. This analysis works best
32
+ with a bounded area of interest within with the data is either clustered,
33
+ dispersed, or randomly distributed. For example, a city's subway stops may
34
+ look extremely clustered if the study area is an entire state. On the other
35
+ hand, they may look rather evenly dispersed if the study area is limited to
36
+ the city's downtown.
34
37
 
35
38
  **Bibliography**
36
39
 
37
40
  Philip J. Clark and Francis C. Evans, “Distance to Nearest Neighbor as a
38
- Measure of Spatial Relationships in Populations,” _Ecology_ 35, no. 4
41
+ Measure of Spatial Relationships in Populations,” *Ecology* 35, no. 4
39
42
  (1954): 445–453, doi:[10.2307/1931034][5].
40
43
 
41
- **Parameters**
44
+ ### Parameters
45
+
46
+ * `dataset` **[FeatureCollection][6]\<any>** FeatureCollection (pref. of points) to study
47
+ * `options` **[Object][7]** Optional parameters (optional, default `{}`)
42
48
 
43
- - `dataset` **[FeatureCollection][6]&lt;any>** FeatureCollection (pref. of points) to study
44
- - `options` **[Object][7]** Optional parameters (optional, default `{}`)
45
- - `options.studyArea` **[Feature][8]&lt;[Polygon][9]>?** polygon representing the study area
46
- - `options.units` **[string][10]** unit of measurement for distances and, squared, area. (optional, default `'kilometers'`)
47
- - `options.properties` **[Object][7]** properties (optional, default `{}`)
49
+ * `options.studyArea` **[Feature][8]<[Polygon][9]>?** polygon representing the study area
50
+ * `options.units` **[string][10]** unit of measurement for distances and, squared, area. (optional, default `'kilometers'`)
51
+ * `options.properties` **[Object][7]** properties (optional, default `{}`)
48
52
 
49
- **Examples**
53
+ ### Examples
50
54
 
51
55
  ```javascript
52
56
  var bbox = [-65, 40, -63, 42];
@@ -57,7 +61,7 @@ var nearestNeighborStudyArea = turf.nearestNeighborAnalysis(dataset);
57
61
  var addToMap = [dataset, nearestNeighborStudyArea];
58
62
  ```
59
63
 
60
- Returns **[Feature][8]&lt;[Polygon][9]>** A polygon of the study area or an approximation of one.
64
+ Returns **[Feature][8]<[Polygon][9]>** A polygon of the study area or an approximation of one.
61
65
 
62
66
  [1]: Feature<Polygon>
63
67
 
package/dist/es/index.js CHANGED
@@ -60,29 +60,29 @@ import { convertArea, featureCollection } from "@turf/helpers";
60
60
  function nearestNeighborAnalysis(dataset, options) {
61
61
  // Optional params
62
62
  options = options || {};
63
- var studyArea = options.studyArea || bboxPolygon(bbox(dataset));
64
- var properties = options.properties || {};
65
- var units = options.units || "kilometers";
66
- var features = [];
67
- featureEach(dataset, function (feature) {
63
+ const studyArea = options.studyArea || bboxPolygon(bbox(dataset));
64
+ const properties = options.properties || {};
65
+ const units = options.units || "kilometers";
66
+ const features = [];
67
+ featureEach(dataset, (feature) => {
68
68
  features.push(centroid(feature));
69
69
  });
70
- var n = features.length;
71
- var observedMeanDistance = features
72
- .map(function (feature, index) {
73
- var otherFeatures = featureCollection(features.filter(function (f, i) {
70
+ const n = features.length;
71
+ const observedMeanDistance = features
72
+ .map((feature, index) => {
73
+ const otherFeatures = featureCollection(features.filter((f, i) => {
74
74
  return i !== index;
75
75
  }));
76
76
  // Have to add the ! to make typescript validation pass
77
77
  // see https://stackoverflow.com/a/40350534/1979085
78
- return distance(feature, nearestPoint(feature, otherFeatures).geometry.coordinates, { units: units });
78
+ return distance(feature, nearestPoint(feature, otherFeatures).geometry.coordinates, { units });
79
79
  })
80
- .reduce(function (sum, value) {
80
+ .reduce((sum, value) => {
81
81
  return sum + value;
82
82
  }, 0) / n;
83
- var populationDensity = n / convertArea(area(studyArea), "meters", units);
84
- var expectedMeanDistance = 1 / (2 * Math.sqrt(populationDensity));
85
- var variance = 0.26136 / Math.sqrt(n * populationDensity);
83
+ const populationDensity = n / convertArea(area(studyArea), "meters", units);
84
+ const expectedMeanDistance = 1 / (2 * Math.sqrt(populationDensity));
85
+ const variance = 0.26136 / Math.sqrt(n * populationDensity);
86
86
  properties.nearestNeighborAnalysis = {
87
87
  units: units,
88
88
  arealUnits: units + "²",
@@ -1,4 +1,5 @@
1
- import { FeatureCollection, Feature, Polygon, Units, Properties } from "@turf/helpers";
1
+ import { FeatureCollection, Feature, Polygon, GeoJsonProperties } from "geojson";
2
+ import { Units } from "@turf/helpers";
2
3
  export interface NearestNeighborStatistics {
3
4
  units: Units;
4
5
  arealUnits: string;
@@ -67,6 +68,6 @@ export interface NearestNeighborStudyArea extends Feature<Polygon> {
67
68
  declare function nearestNeighborAnalysis(dataset: FeatureCollection<any>, options?: {
68
69
  studyArea?: Feature<Polygon>;
69
70
  units?: Units;
70
- properties?: Properties;
71
+ properties?: GeoJsonProperties;
71
72
  }): NearestNeighborStudyArea;
72
73
  export default nearestNeighborAnalysis;
package/dist/js/index.js CHANGED
@@ -1,16 +1,14 @@
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 area_1 = __importDefault(require("@turf/area"));
7
- var bbox_1 = __importDefault(require("@turf/bbox"));
8
- var bbox_polygon_1 = __importDefault(require("@turf/bbox-polygon"));
9
- var centroid_1 = __importDefault(require("@turf/centroid"));
10
- var distance_1 = __importDefault(require("@turf/distance"));
11
- var nearest_point_1 = __importDefault(require("@turf/nearest-point"));
12
- var meta_1 = require("@turf/meta");
13
- var helpers_1 = require("@turf/helpers");
3
+ const tslib_1 = require("tslib");
4
+ const area_1 = tslib_1.__importDefault(require("@turf/area"));
5
+ const bbox_1 = tslib_1.__importDefault(require("@turf/bbox"));
6
+ const bbox_polygon_1 = tslib_1.__importDefault(require("@turf/bbox-polygon"));
7
+ const centroid_1 = tslib_1.__importDefault(require("@turf/centroid"));
8
+ const distance_1 = tslib_1.__importDefault(require("@turf/distance"));
9
+ const nearest_point_1 = tslib_1.__importDefault(require("@turf/nearest-point"));
10
+ const meta_1 = require("@turf/meta");
11
+ const helpers_1 = require("@turf/helpers");
14
12
  /**
15
13
  * Nearest Neighbor Analysis calculates an index based the average distances
16
14
  * between points in the dataset, thereby providing inference as to whether the
@@ -65,29 +63,29 @@ var helpers_1 = require("@turf/helpers");
65
63
  function nearestNeighborAnalysis(dataset, options) {
66
64
  // Optional params
67
65
  options = options || {};
68
- var studyArea = options.studyArea || bbox_polygon_1.default(bbox_1.default(dataset));
69
- var properties = options.properties || {};
70
- var units = options.units || "kilometers";
71
- var features = [];
72
- meta_1.featureEach(dataset, function (feature) {
66
+ const studyArea = options.studyArea || bbox_polygon_1.default(bbox_1.default(dataset));
67
+ const properties = options.properties || {};
68
+ const units = options.units || "kilometers";
69
+ const features = [];
70
+ meta_1.featureEach(dataset, (feature) => {
73
71
  features.push(centroid_1.default(feature));
74
72
  });
75
- var n = features.length;
76
- var observedMeanDistance = features
77
- .map(function (feature, index) {
78
- var otherFeatures = helpers_1.featureCollection(features.filter(function (f, i) {
73
+ const n = features.length;
74
+ const observedMeanDistance = features
75
+ .map((feature, index) => {
76
+ const otherFeatures = helpers_1.featureCollection(features.filter((f, i) => {
79
77
  return i !== index;
80
78
  }));
81
79
  // Have to add the ! to make typescript validation pass
82
80
  // see https://stackoverflow.com/a/40350534/1979085
83
- return distance_1.default(feature, nearest_point_1.default(feature, otherFeatures).geometry.coordinates, { units: units });
81
+ return distance_1.default(feature, nearest_point_1.default(feature, otherFeatures).geometry.coordinates, { units });
84
82
  })
85
- .reduce(function (sum, value) {
83
+ .reduce((sum, value) => {
86
84
  return sum + value;
87
85
  }, 0) / n;
88
- var populationDensity = n / helpers_1.convertArea(area_1.default(studyArea), "meters", units);
89
- var expectedMeanDistance = 1 / (2 * Math.sqrt(populationDensity));
90
- var variance = 0.26136 / Math.sqrt(n * populationDensity);
86
+ const populationDensity = n / helpers_1.convertArea(area_1.default(studyArea), "meters", units);
87
+ const expectedMeanDistance = 1 / (2 * Math.sqrt(populationDensity));
88
+ const variance = 0.26136 / Math.sqrt(n * populationDensity);
91
89
  properties.nearestNeighborAnalysis = {
92
90
  units: units,
93
91
  arealUnits: units + "²",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/nearest-neighbor-analysis",
3
- "version": "6.5.0",
3
+ "version": "7.0.0-alpha.0",
4
4
  "description": "turf nearest-neighbor-analysis module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -47,7 +47,7 @@
47
47
  "test:tape": "ts-node -r esm test.js"
48
48
  },
49
49
  "devDependencies": {
50
- "@turf/truncate": "^6.5.0",
50
+ "@turf/truncate": "^7.0.0-alpha.0",
51
51
  "@types/tape": "*",
52
52
  "benchmark": "*",
53
53
  "load-json-file": "*",
@@ -59,14 +59,15 @@
59
59
  "write-json-file": "*"
60
60
  },
61
61
  "dependencies": {
62
- "@turf/area": "^6.5.0",
63
- "@turf/bbox": "^6.5.0",
64
- "@turf/bbox-polygon": "^6.5.0",
65
- "@turf/centroid": "^6.5.0",
66
- "@turf/distance": "^6.5.0",
67
- "@turf/helpers": "^6.5.0",
68
- "@turf/meta": "^6.5.0",
69
- "@turf/nearest-point": "^6.5.0"
62
+ "@turf/area": "^7.0.0-alpha.0",
63
+ "@turf/bbox": "^7.0.0-alpha.0",
64
+ "@turf/bbox-polygon": "^7.0.0-alpha.0",
65
+ "@turf/centroid": "^7.0.0-alpha.0",
66
+ "@turf/distance": "^7.0.0-alpha.0",
67
+ "@turf/helpers": "^7.0.0-alpha.0",
68
+ "@turf/meta": "^7.0.0-alpha.0",
69
+ "@turf/nearest-point": "^7.0.0-alpha.0",
70
+ "tslib": "^2.3.0"
70
71
  },
71
- "gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
72
+ "gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
72
73
  }