@turf/nearest-neighbor-analysis 7.2.0 → 7.3.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 +1 -1
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +17 -17
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ Type: [object][1]
|
|
|
30
30
|
|
|
31
31
|
## nearestNeighborAnalysis
|
|
32
32
|
|
|
33
|
-
Nearest Neighbor Analysis calculates an index based the average distances
|
|
33
|
+
Nearest Neighbor Analysis calculates an index based on the average distances
|
|
34
34
|
between points in the dataset, thereby providing inference as to whether the
|
|
35
35
|
data is clustered, dispersed, or randomly distributed within the study area.
|
|
36
36
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -49,9 +49,9 @@ function nearestNeighborAnalysis(dataset, options) {
|
|
|
49
49
|
studyArea.properties = properties;
|
|
50
50
|
return studyArea;
|
|
51
51
|
}
|
|
52
|
-
var
|
|
52
|
+
var index_default = nearestNeighborAnalysis;
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
exports.default =
|
|
56
|
+
exports.default = index_default; exports.nearestNeighborAnalysis = nearestNeighborAnalysis;
|
|
57
57
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-nearest-neighbor-analysis/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACOA,kCAAqB;AACrB,kCAAqB;AACrB,iDAA4B;AAC5B,0CAAyB;AACzB,0CAAyB;AACzB,mDAA6B;AAC7B,kCAA4B;AAC5B;AACE;AACA;AAAA,wCAGK;AAwFP,SAAS,uBAAA,CACP,O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B,MAAA,EAAA,CAAS,qBAAA,EAAuB,oBAAA,EAAA,EAAwB;AAAA,EAC1D,CAAA;AACA,EAAA,SAAA,CAAU,WAAA,EAAa,UAAA;AAEvB,EAAA,OAAO,SAAA;AACT;AAOA,IAAO,cAAA,EAAQ,uBAAA;ADpHf;AACE;AACA;AACF,2FAAC","file":"/home/runner/work/turf/turf/packages/turf-nearest-neighbor-analysis/dist/cjs/index.cjs","sourcesContent":[null,"import {\n FeatureCollection,\n Feature,\n Point,\n Polygon,\n GeoJsonProperties,\n} from \"geojson\";\nimport { area } from \"@turf/area\";\nimport { bbox } from \"@turf/bbox\";\nimport { bboxPolygon } from \"@turf/bbox-polygon\";\nimport { centroid } from \"@turf/centroid\";\nimport { distance } from \"@turf/distance\";\nimport { nearestPoint } from \"@turf/nearest-point\";\nimport { featureEach } from \"@turf/meta\";\nimport {\n convertArea,\n featureCollection,\n Units,\n AreaUnits,\n} from \"@turf/helpers\";\n\n/**\n * Nearest neighbour statistics.\n *\n * @typedef {object} NearestNeighborStatistics\n * @property {(Units & AreaUnits)} units\n * @property {string} arealUnits\n * @property {number} observedMeanDistance\n * @property {number} expectedMeanDistance\n * @property {number} numberOfPoints\n * @property {number} zScore\n */\ninterface NearestNeighborStatistics {\n units: Units & AreaUnits;\n arealUnits: string;\n observedMeanDistance: number;\n expectedMeanDistance: number;\n numberOfPoints: number;\n zScore: number;\n}\n\n/**\n * Nearest neighbour study area polygon feature.\n *\n * @typedef {object} NearestNeighborStudyArea\n * @extends Feature<Polygon>\n * @property {GeoJsonProperties} properties\n * @property {NearestNeighborStatistics} properties.nearestNeighborAnalysis\n */\ninterface NearestNeighborStudyArea extends Feature<Polygon> {\n properties: {\n nearestNeighborAnalysis: NearestNeighborStatistics;\n [key: string]: any;\n };\n}\n\n/**\n * Nearest Neighbor Analysis calculates an index based on the average distances\n * between points in the dataset, thereby providing inference as to whether the\n * data is clustered, dispersed, or randomly distributed within the study area.\n *\n * It returns a {@link Feature}<{@link Polygon}> of the study area, with the results of\n * the analysis attached as part of of the `nearestNeighborAnalysis` property\n * of the study area's `properties`. The attached\n * [_z_-score](https://en.wikipedia.org/wiki/Standard_score) indicates how many\n * standard deviations above or below the expected mean distance the data's\n * observed mean distance is. The more negative, the more clustered. The more\n * positive, the more evenly dispersed. A _z_-score between -2 and 2 indicates\n * a seemingly random distribution. That is, within _p_ of less than 0.05, the\n * distribution appears statistically significantly neither clustered nor\n * dispersed.\n *\n * **Remarks**\n *\n * - Though the analysis will work on any {@link FeatureCollection} type, it\n * works best with {@link Point} collections.\n *\n * - This analysis is _very_ sensitive to the study area provided.\n * If no {@link Feature}<{@link Polygon}> is passed as the study area, the function draws a box\n * around the data, which may distort the findings. This analysis works best\n * with a bounded area of interest within with the data is either clustered,\n * dispersed, or randomly distributed. For example, a city's subway stops may\n * look extremely clustered if the study area is an entire state. On the other\n * hand, they may look rather evenly dispersed if the study area is limited to\n * the city's downtown.\n *\n * **Bibliography**\n *\n * Philip J. Clark and Francis C. Evans, “Distance to Nearest Neighbor as a\n * Measure of Spatial Relationships in Populations,” _Ecology_ 35, no. 4\n * (1954): 445–453, doi:[10.2307/1931034](http://doi.org/10.2307/1931034).\n *\n * @function\n * @param {FeatureCollection<any>} dataset FeatureCollection (pref. of points) to study\n * @param {Object} [options={}] Optional parameters\n * @param {Feature<Polygon>} [options.studyArea] polygon representing the study area\n * @param {Units & AreaUnits} [options.units='kilometers'] unit of measurement for distances and, squared, area.\n * @param {GeoJsonProperties} [options.properties={}] properties\n * @returns {NearestNeighborStudyArea} A polygon of the study area or an approximation of one.\n * @example\n * var bbox = [-65, 40, -63, 42];\n * var dataset = turf.randomPoint(100, { bbox: bbox });\n * var nearestNeighborStudyArea = turf.nearestNeighborAnalysis(dataset);\n *\n * //addToMap\n * var addToMap = [dataset, nearestNeighborStudyArea];\n */\nfunction nearestNeighborAnalysis(\n dataset: FeatureCollection<any>,\n options?: {\n studyArea?: Feature<Polygon>;\n units?: Units & AreaUnits;\n properties?: GeoJsonProperties;\n }\n): NearestNeighborStudyArea {\n // Optional params\n options = options || {};\n const studyArea = options.studyArea || bboxPolygon(bbox(dataset));\n const properties = options.properties || {};\n const units = options.units || \"kilometers\";\n\n const features: Array<Feature<Point>> = [];\n featureEach(dataset, (feature) => {\n features.push(centroid(feature));\n });\n const n = features.length;\n const observedMeanDistance =\n features\n .map((feature, index) => {\n const otherFeatures = featureCollection<Point>(\n features.filter((f, i) => {\n return i !== index;\n })\n );\n // Have to add the ! to make typescript validation pass\n // see https://stackoverflow.com/a/40350534/1979085\n return distance(\n feature,\n nearestPoint(feature, otherFeatures).geometry!.coordinates,\n { units }\n );\n })\n .reduce((sum, value) => {\n return sum + value;\n }, 0) / n;\n\n const populationDensity = n / convertArea(area(studyArea), \"meters\", units);\n const expectedMeanDistance = 1 / (2 * Math.sqrt(populationDensity));\n const variance = 0.26136 / Math.sqrt(n * populationDensity);\n properties.nearestNeighborAnalysis = {\n units: units,\n arealUnits: units + \"²\",\n observedMeanDistance: observedMeanDistance,\n expectedMeanDistance: expectedMeanDistance,\n nearestNeighborIndex: observedMeanDistance / expectedMeanDistance,\n numberOfPoints: n,\n zScore: (observedMeanDistance - expectedMeanDistance) / variance,\n };\n studyArea.properties = properties;\n\n return studyArea as NearestNeighborStudyArea;\n}\n\nexport {\n nearestNeighborAnalysis,\n NearestNeighborStatistics,\n NearestNeighborStudyArea,\n};\nexport default nearestNeighborAnalysis;\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Feature, Polygon,
|
|
1
|
+
import { FeatureCollection, Feature, Polygon, GeoJsonProperties } from 'geojson';
|
|
2
2
|
import { Units, AreaUnits } from '@turf/helpers';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -35,7 +35,7 @@ interface NearestNeighborStudyArea extends Feature<Polygon> {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* Nearest Neighbor Analysis calculates an index based the average distances
|
|
38
|
+
* Nearest Neighbor Analysis calculates an index based on the average distances
|
|
39
39
|
* between points in the dataset, thereby providing inference as to whether the
|
|
40
40
|
* data is clustered, dispersed, or randomly distributed within the study area.
|
|
41
41
|
*
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Feature, Polygon,
|
|
1
|
+
import { FeatureCollection, Feature, Polygon, GeoJsonProperties } from 'geojson';
|
|
2
2
|
import { Units, AreaUnits } from '@turf/helpers';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -35,7 +35,7 @@ interface NearestNeighborStudyArea extends Feature<Polygon> {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* Nearest Neighbor Analysis calculates an index based the average distances
|
|
38
|
+
* Nearest Neighbor Analysis calculates an index based on the average distances
|
|
39
39
|
* between points in the dataset, thereby providing inference as to whether the
|
|
40
40
|
* data is clustered, dispersed, or randomly distributed within the study area.
|
|
41
41
|
*
|
package/dist/esm/index.js
CHANGED
|
@@ -49,9 +49,9 @@ function nearestNeighborAnalysis(dataset, options) {
|
|
|
49
49
|
studyArea.properties = properties;
|
|
50
50
|
return studyArea;
|
|
51
51
|
}
|
|
52
|
-
var
|
|
52
|
+
var index_default = nearestNeighborAnalysis;
|
|
53
53
|
export {
|
|
54
|
-
|
|
54
|
+
index_default as default,
|
|
55
55
|
nearestNeighborAnalysis
|
|
56
56
|
};
|
|
57
57
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import {\n FeatureCollection,\n Feature,\n Point,\n Polygon,\n GeoJsonProperties,\n} from \"geojson\";\nimport { area } from \"@turf/area\";\nimport { bbox } from \"@turf/bbox\";\nimport { bboxPolygon } from \"@turf/bbox-polygon\";\nimport { centroid } from \"@turf/centroid\";\nimport { distance } from \"@turf/distance\";\nimport { nearestPoint } from \"@turf/nearest-point\";\nimport { featureEach } from \"@turf/meta\";\nimport {\n convertArea,\n featureCollection,\n Units,\n AreaUnits,\n} from \"@turf/helpers\";\n\n/**\n * Nearest neighbour statistics.\n *\n * @typedef {object} NearestNeighborStatistics\n * @property {(Units & AreaUnits)} units\n * @property {string} arealUnits\n * @property {number} observedMeanDistance\n * @property {number} expectedMeanDistance\n * @property {number} numberOfPoints\n * @property {number} zScore\n */\ninterface NearestNeighborStatistics {\n units: Units & AreaUnits;\n arealUnits: string;\n observedMeanDistance: number;\n expectedMeanDistance: number;\n numberOfPoints: number;\n zScore: number;\n}\n\n/**\n * Nearest neighbour study area polygon feature.\n *\n * @typedef {object} NearestNeighborStudyArea\n * @extends Feature<Polygon>\n * @property {GeoJsonProperties} properties\n * @property {NearestNeighborStatistics} properties.nearestNeighborAnalysis\n */\ninterface NearestNeighborStudyArea extends Feature<Polygon> {\n properties: {\n nearestNeighborAnalysis: NearestNeighborStatistics;\n [key: string]: any;\n };\n}\n\n/**\n * Nearest Neighbor Analysis calculates an index based the average distances\n * between points in the dataset, thereby providing inference as to whether the\n * data is clustered, dispersed, or randomly distributed within the study area.\n *\n * It returns a {@link Feature}<{@link Polygon}> of the study area, with the results of\n * the analysis attached as part of of the `nearestNeighborAnalysis` property\n * of the study area's `properties`. The attached\n * [_z_-score](https://en.wikipedia.org/wiki/Standard_score) indicates how many\n * standard deviations above or below the expected mean distance the data's\n * observed mean distance is. The more negative, the more clustered. The more\n * positive, the more evenly dispersed. A _z_-score between -2 and 2 indicates\n * a seemingly random distribution. That is, within _p_ of less than 0.05, the\n * distribution appears statistically significantly neither clustered nor\n * dispersed.\n *\n * **Remarks**\n *\n * - Though the analysis will work on any {@link FeatureCollection} type, it\n * works best with {@link Point} collections.\n *\n * - This analysis is _very_ sensitive to the study area provided.\n * If no {@link Feature}<{@link Polygon}> is passed as the study area, the function draws a box\n * around the data, which may distort the findings. This analysis works best\n * with a bounded area of interest within with the data is either clustered,\n * dispersed, or randomly distributed. For example, a city's subway stops may\n * look extremely clustered if the study area is an entire state. On the other\n * hand, they may look rather evenly dispersed if the study area is limited to\n * the city's downtown.\n *\n * **Bibliography**\n *\n * Philip J. Clark and Francis C. Evans, “Distance to Nearest Neighbor as a\n * Measure of Spatial Relationships in Populations,” _Ecology_ 35, no. 4\n * (1954): 445–453, doi:[10.2307/1931034](http://doi.org/10.2307/1931034).\n *\n * @function\n * @param {FeatureCollection<any>} dataset FeatureCollection (pref. of points) to study\n * @param {Object} [options={}] Optional parameters\n * @param {Feature<Polygon>} [options.studyArea] polygon representing the study area\n * @param {Units & AreaUnits} [options.units='kilometers'] unit of measurement for distances and, squared, area.\n * @param {GeoJsonProperties} [options.properties={}] properties\n * @returns {NearestNeighborStudyArea} A polygon of the study area or an approximation of one.\n * @example\n * var bbox = [-65, 40, -63, 42];\n * var dataset = turf.randomPoint(100, { bbox: bbox });\n * var nearestNeighborStudyArea = turf.nearestNeighborAnalysis(dataset);\n *\n * //addToMap\n * var addToMap = [dataset, nearestNeighborStudyArea];\n */\nfunction nearestNeighborAnalysis(\n dataset: FeatureCollection<any>,\n options?: {\n studyArea?: Feature<Polygon>;\n units?: Units & AreaUnits;\n properties?: GeoJsonProperties;\n }\n): NearestNeighborStudyArea {\n // Optional params\n options = options || {};\n const studyArea = options.studyArea || bboxPolygon(bbox(dataset));\n const properties = options.properties || {};\n const units = options.units || \"kilometers\";\n\n const features: Array<Feature<Point>> = [];\n featureEach(dataset, (feature) => {\n features.push(centroid(feature));\n });\n const n = features.length;\n const observedMeanDistance =\n features\n .map((feature, index) => {\n const otherFeatures = featureCollection<Point>(\n features.filter((f, i) => {\n return i !== index;\n })\n );\n // Have to add the ! to make typescript validation pass\n // see https://stackoverflow.com/a/40350534/1979085\n return distance(\n feature,\n nearestPoint(feature, otherFeatures).geometry!.coordinates,\n { units }\n );\n })\n .reduce((sum, value) => {\n return sum + value;\n }, 0) / n;\n\n const populationDensity = n / convertArea(area(studyArea), \"meters\", units);\n const expectedMeanDistance = 1 / (2 * Math.sqrt(populationDensity));\n const variance = 0.26136 / Math.sqrt(n * populationDensity);\n properties.nearestNeighborAnalysis = {\n units: units,\n arealUnits: units + \"²\",\n observedMeanDistance: observedMeanDistance,\n expectedMeanDistance: expectedMeanDistance,\n nearestNeighborIndex: observedMeanDistance / expectedMeanDistance,\n numberOfPoints: n,\n zScore: (observedMeanDistance - expectedMeanDistance) / variance,\n };\n studyArea.properties = properties;\n\n return studyArea as NearestNeighborStudyArea;\n}\n\nexport {\n nearestNeighborAnalysis,\n NearestNeighborStatistics,\n NearestNeighborStudyArea,\n};\nexport default nearestNeighborAnalysis;\n"],"mappings":";AAOA,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAwFP,SAAS,wBACP,SACA,SAK0B;AAE1B,YAAU,WAAW,CAAC;AACtB,QAAM,YAAY,QAAQ,aAAa,YAAY,KAAK,OAAO,CAAC;AAChE,QAAM,aAAa,QAAQ,cAAc,CAAC;AAC1C,QAAM,QAAQ,QAAQ,SAAS;AAE/B,QAAM,WAAkC,CAAC;AACzC,cAAY,SAAS,CAAC,YAAY;AAChC,aAAS,KAAK,SAAS,OAAO,CAAC;AAAA,EACjC,CAAC;AACD,QAAM,IAAI,SAAS;AACnB,QAAM,uBACJ,SACG,IAAI,CAAC,SAAS,UAAU;AACvB,UAAM,gBAAgB;AAAA,MACpB,SAAS,OAAO,CAAC,GAAG,MAAM;AACxB,eAAO,MAAM;AAAA,MACf,CAAC;AAAA,IACH;AAGA,WAAO;AAAA,MACL;AAAA,MACA,aAAa,SAAS,aAAa,EAAE,SAAU;AAAA,MAC/C,EAAE,MAAM;AAAA,IACV;AAAA,EACF,CAAC,EACA,OAAO,CAAC,KAAK,UAAU;AACtB,WAAO,MAAM;AAAA,EACf,GAAG,CAAC,IAAI;AAEZ,QAAM,oBAAoB,IAAI,YAAY,KAAK,SAAS,GAAG,UAAU,KAAK;AAC1E,QAAM,uBAAuB,KAAK,IAAI,KAAK,KAAK,iBAAiB;AACjE,QAAM,WAAW,UAAU,KAAK,KAAK,IAAI,iBAAiB;AAC1D,aAAW,0BAA0B;AAAA,IACnC;AAAA,IACA,YAAY,QAAQ;AAAA,IACpB;AAAA,IACA;AAAA,IACA,sBAAsB,uBAAuB;AAAA,IAC7C,gBAAgB;AAAA,IAChB,SAAS,uBAAuB,wBAAwB;AAAA,EAC1D;AACA,YAAU,aAAa;AAEvB,SAAO;AACT;AAOA,IAAO,
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import {\n FeatureCollection,\n Feature,\n Point,\n Polygon,\n GeoJsonProperties,\n} from \"geojson\";\nimport { area } from \"@turf/area\";\nimport { bbox } from \"@turf/bbox\";\nimport { bboxPolygon } from \"@turf/bbox-polygon\";\nimport { centroid } from \"@turf/centroid\";\nimport { distance } from \"@turf/distance\";\nimport { nearestPoint } from \"@turf/nearest-point\";\nimport { featureEach } from \"@turf/meta\";\nimport {\n convertArea,\n featureCollection,\n Units,\n AreaUnits,\n} from \"@turf/helpers\";\n\n/**\n * Nearest neighbour statistics.\n *\n * @typedef {object} NearestNeighborStatistics\n * @property {(Units & AreaUnits)} units\n * @property {string} arealUnits\n * @property {number} observedMeanDistance\n * @property {number} expectedMeanDistance\n * @property {number} numberOfPoints\n * @property {number} zScore\n */\ninterface NearestNeighborStatistics {\n units: Units & AreaUnits;\n arealUnits: string;\n observedMeanDistance: number;\n expectedMeanDistance: number;\n numberOfPoints: number;\n zScore: number;\n}\n\n/**\n * Nearest neighbour study area polygon feature.\n *\n * @typedef {object} NearestNeighborStudyArea\n * @extends Feature<Polygon>\n * @property {GeoJsonProperties} properties\n * @property {NearestNeighborStatistics} properties.nearestNeighborAnalysis\n */\ninterface NearestNeighborStudyArea extends Feature<Polygon> {\n properties: {\n nearestNeighborAnalysis: NearestNeighborStatistics;\n [key: string]: any;\n };\n}\n\n/**\n * Nearest Neighbor Analysis calculates an index based on the average distances\n * between points in the dataset, thereby providing inference as to whether the\n * data is clustered, dispersed, or randomly distributed within the study area.\n *\n * It returns a {@link Feature}<{@link Polygon}> of the study area, with the results of\n * the analysis attached as part of of the `nearestNeighborAnalysis` property\n * of the study area's `properties`. The attached\n * [_z_-score](https://en.wikipedia.org/wiki/Standard_score) indicates how many\n * standard deviations above or below the expected mean distance the data's\n * observed mean distance is. The more negative, the more clustered. The more\n * positive, the more evenly dispersed. A _z_-score between -2 and 2 indicates\n * a seemingly random distribution. That is, within _p_ of less than 0.05, the\n * distribution appears statistically significantly neither clustered nor\n * dispersed.\n *\n * **Remarks**\n *\n * - Though the analysis will work on any {@link FeatureCollection} type, it\n * works best with {@link Point} collections.\n *\n * - This analysis is _very_ sensitive to the study area provided.\n * If no {@link Feature}<{@link Polygon}> is passed as the study area, the function draws a box\n * around the data, which may distort the findings. This analysis works best\n * with a bounded area of interest within with the data is either clustered,\n * dispersed, or randomly distributed. For example, a city's subway stops may\n * look extremely clustered if the study area is an entire state. On the other\n * hand, they may look rather evenly dispersed if the study area is limited to\n * the city's downtown.\n *\n * **Bibliography**\n *\n * Philip J. Clark and Francis C. Evans, “Distance to Nearest Neighbor as a\n * Measure of Spatial Relationships in Populations,” _Ecology_ 35, no. 4\n * (1954): 445–453, doi:[10.2307/1931034](http://doi.org/10.2307/1931034).\n *\n * @function\n * @param {FeatureCollection<any>} dataset FeatureCollection (pref. of points) to study\n * @param {Object} [options={}] Optional parameters\n * @param {Feature<Polygon>} [options.studyArea] polygon representing the study area\n * @param {Units & AreaUnits} [options.units='kilometers'] unit of measurement for distances and, squared, area.\n * @param {GeoJsonProperties} [options.properties={}] properties\n * @returns {NearestNeighborStudyArea} A polygon of the study area or an approximation of one.\n * @example\n * var bbox = [-65, 40, -63, 42];\n * var dataset = turf.randomPoint(100, { bbox: bbox });\n * var nearestNeighborStudyArea = turf.nearestNeighborAnalysis(dataset);\n *\n * //addToMap\n * var addToMap = [dataset, nearestNeighborStudyArea];\n */\nfunction nearestNeighborAnalysis(\n dataset: FeatureCollection<any>,\n options?: {\n studyArea?: Feature<Polygon>;\n units?: Units & AreaUnits;\n properties?: GeoJsonProperties;\n }\n): NearestNeighborStudyArea {\n // Optional params\n options = options || {};\n const studyArea = options.studyArea || bboxPolygon(bbox(dataset));\n const properties = options.properties || {};\n const units = options.units || \"kilometers\";\n\n const features: Array<Feature<Point>> = [];\n featureEach(dataset, (feature) => {\n features.push(centroid(feature));\n });\n const n = features.length;\n const observedMeanDistance =\n features\n .map((feature, index) => {\n const otherFeatures = featureCollection<Point>(\n features.filter((f, i) => {\n return i !== index;\n })\n );\n // Have to add the ! to make typescript validation pass\n // see https://stackoverflow.com/a/40350534/1979085\n return distance(\n feature,\n nearestPoint(feature, otherFeatures).geometry!.coordinates,\n { units }\n );\n })\n .reduce((sum, value) => {\n return sum + value;\n }, 0) / n;\n\n const populationDensity = n / convertArea(area(studyArea), \"meters\", units);\n const expectedMeanDistance = 1 / (2 * Math.sqrt(populationDensity));\n const variance = 0.26136 / Math.sqrt(n * populationDensity);\n properties.nearestNeighborAnalysis = {\n units: units,\n arealUnits: units + \"²\",\n observedMeanDistance: observedMeanDistance,\n expectedMeanDistance: expectedMeanDistance,\n nearestNeighborIndex: observedMeanDistance / expectedMeanDistance,\n numberOfPoints: n,\n zScore: (observedMeanDistance - expectedMeanDistance) / variance,\n };\n studyArea.properties = properties;\n\n return studyArea as NearestNeighborStudyArea;\n}\n\nexport {\n nearestNeighborAnalysis,\n NearestNeighborStatistics,\n NearestNeighborStudyArea,\n};\nexport default nearestNeighborAnalysis;\n"],"mappings":";AAOA,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B;AAAA,EACE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|
|
3
|
+
"version": "7.3.0",
|
|
4
|
+
"description": "Calculates an index based the average distances between points in the dataset, thereby providing inference as to whether the data is clustered, dispersed, or randomly distributed within the study area.",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Moacir P. de Sá Pereira <@muziejus>"
|
|
@@ -52,29 +52,29 @@
|
|
|
52
52
|
"test:tape": "tsx test.ts"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@turf/truncate": "
|
|
55
|
+
"@turf/truncate": "7.3.0",
|
|
56
56
|
"@types/benchmark": "^2.1.5",
|
|
57
|
-
"@types/tape": "^
|
|
57
|
+
"@types/tape": "^5.8.1",
|
|
58
58
|
"benchmark": "^2.1.4",
|
|
59
59
|
"load-json-file": "^7.0.1",
|
|
60
60
|
"npm-run-all": "^4.1.5",
|
|
61
61
|
"tape": "^5.9.0",
|
|
62
|
-
"tsup": "^8.
|
|
63
|
-
"tsx": "^4.19.
|
|
64
|
-
"typescript": "^5.
|
|
65
|
-
"write-json-file": "^
|
|
62
|
+
"tsup": "^8.4.0",
|
|
63
|
+
"tsx": "^4.19.4",
|
|
64
|
+
"typescript": "^5.8.3",
|
|
65
|
+
"write-json-file": "^6.0.0"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@turf/area": "
|
|
69
|
-
"@turf/bbox": "
|
|
70
|
-
"@turf/bbox-polygon": "
|
|
71
|
-
"@turf/centroid": "
|
|
72
|
-
"@turf/distance": "
|
|
73
|
-
"@turf/helpers": "
|
|
74
|
-
"@turf/meta": "
|
|
75
|
-
"@turf/nearest-point": "
|
|
68
|
+
"@turf/area": "7.3.0",
|
|
69
|
+
"@turf/bbox": "7.3.0",
|
|
70
|
+
"@turf/bbox-polygon": "7.3.0",
|
|
71
|
+
"@turf/centroid": "7.3.0",
|
|
72
|
+
"@turf/distance": "7.3.0",
|
|
73
|
+
"@turf/helpers": "7.3.0",
|
|
74
|
+
"@turf/meta": "7.3.0",
|
|
75
|
+
"@turf/nearest-point": "7.3.0",
|
|
76
76
|
"@types/geojson": "^7946.0.10",
|
|
77
77
|
"tslib": "^2.8.1"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "9f58a103e8f9a587ab640307ed03ba5233913ddd"
|
|
80
80
|
}
|