@turf/nearest-neighbor-analysis 7.2.0 → 7.3.1

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
@@ -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
 
@@ -49,9 +49,9 @@ function nearestNeighborAnalysis(dataset, options) {
49
49
  studyArea.properties = properties;
50
50
  return studyArea;
51
51
  }
52
- var turf_nearest_neighbor_analysis_default = nearestNeighborAnalysis;
52
+ var index_default = nearestNeighborAnalysis;
53
53
 
54
54
 
55
55
 
56
- exports.default = turf_nearest_neighbor_analysis_default; exports.nearestNeighborAnalysis = nearestNeighborAnalysis;
56
+ exports.default = index_default; exports.nearestNeighborAnalysis = nearestNeighborAnalysis;
57
57
  //# sourceMappingURL=index.cjs.map
@@ -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,OAAA,EACA,OAAA,EAK0B;AAE1B,EAAA,QAAA,EAAU,QAAA,GAAW,CAAC,CAAA;AACtB,EAAA,MAAM,UAAA,EAAY,OAAA,CAAQ,UAAA,GAAa,sCAAA,wBAAY,OAAY,CAAC,CAAA;AAChE,EAAA,MAAM,WAAA,EAAa,OAAA,CAAQ,WAAA,GAAc,CAAC,CAAA;AAC1C,EAAA,MAAM,MAAA,EAAQ,OAAA,CAAQ,MAAA,GAAS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pB,oBAAA;AAAA,IACA,oBAAA;AAAA,IACA,oBAAA,EAAsB,qBAAA,EAAuB,oBAAA;AAAA,IAC7C,cAAA,EAAgB,CAAA;AAAA,IAChB,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,uCAAA,EAAQ,uBAAA;ADpHf;AACE;AACA;AACF,oHAAC","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 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"]}
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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AK,CAAA;AAC1E,EAAA,MAAM,qBAAA,EAAuB,EAAA,EAAA,CAAK,EAAA,EAAI,IAAA,CAAK,IAAA,CAAK,iBAAiB,CAAA,CAAA;AACjE,EAAA,MAAM,SAAA,EAAW,QAAA,EAAU,IAAA,CAAK,IAAA,CAAK,EAAA,EAAI,iBAAiB,CAAA;AAC1D,EAAA,UAAA,CAAW,wBAAA,EAA0B;AAAA,IACnC,KAAA;AAAA,IACA,UAAA,EAAY,MAAA,EAAQ,MAAA;AAAA,IACpB,oBAAA;AAAA,IACA,oBAAA;AAAA,IACA,oBAAA,EAAsB,qBAAA,EAAuB,oBAAA;AAAA,IAC7C,cAAA,EAAgB,CAAA;AAAA,IAChB,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"]}
@@ -1,4 +1,4 @@
1
- import { Feature, Polygon, FeatureCollection, GeoJsonProperties } from 'geojson';
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
  *
@@ -1,4 +1,4 @@
1
- import { Feature, Polygon, FeatureCollection, GeoJsonProperties } from 'geojson';
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 turf_nearest_neighbor_analysis_default = nearestNeighborAnalysis;
52
+ var index_default = nearestNeighborAnalysis;
53
53
  export {
54
- turf_nearest_neighbor_analysis_default as default,
54
+ index_default as default,
55
55
  nearestNeighborAnalysis
56
56
  };
57
57
  //# sourceMappingURL=index.js.map
@@ -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,yCAAQ;","names":[]}
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 NearestNeighborStudyAr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;AACA,YAAU,aAAa;AAEvB,SAAO;AACT;AAOA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@turf/nearest-neighbor-analysis",
3
- "version": "7.2.0",
4
- "description": "turf nearest-neighbor-analysis module",
3
+ "version": "7.3.1",
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>"
@@ -48,33 +48,32 @@
48
48
  "bench": "tsx bench.ts",
49
49
  "build": "tsup --config ../../tsup.config.ts",
50
50
  "docs": "tsx ../../scripts/generate-readmes.ts",
51
- "test": "npm-run-all --npm-path npm test:*",
51
+ "test": "pnpm run /test:.*/",
52
52
  "test:tape": "tsx test.ts"
53
53
  },
54
54
  "devDependencies": {
55
- "@turf/truncate": "^7.2.0",
55
+ "@turf/truncate": "7.3.1",
56
56
  "@types/benchmark": "^2.1.5",
57
- "@types/tape": "^4.13.4",
57
+ "@types/tape": "^5.8.1",
58
58
  "benchmark": "^2.1.4",
59
59
  "load-json-file": "^7.0.1",
60
- "npm-run-all": "^4.1.5",
61
60
  "tape": "^5.9.0",
62
- "tsup": "^8.3.5",
63
- "tsx": "^4.19.2",
64
- "typescript": "^5.5.4",
65
- "write-json-file": "^5.0.0"
61
+ "tsup": "^8.4.0",
62
+ "tsx": "^4.19.4",
63
+ "typescript": "^5.8.3",
64
+ "write-json-file": "^6.0.0"
66
65
  },
67
66
  "dependencies": {
68
- "@turf/area": "^7.2.0",
69
- "@turf/bbox": "^7.2.0",
70
- "@turf/bbox-polygon": "^7.2.0",
71
- "@turf/centroid": "^7.2.0",
72
- "@turf/distance": "^7.2.0",
73
- "@turf/helpers": "^7.2.0",
74
- "@turf/meta": "^7.2.0",
75
- "@turf/nearest-point": "^7.2.0",
67
+ "@turf/area": "7.3.1",
68
+ "@turf/bbox": "7.3.1",
69
+ "@turf/bbox-polygon": "7.3.1",
70
+ "@turf/centroid": "7.3.1",
71
+ "@turf/distance": "7.3.1",
72
+ "@turf/helpers": "7.3.1",
73
+ "@turf/meta": "7.3.1",
74
+ "@turf/nearest-point": "7.3.1",
76
75
  "@types/geojson": "^7946.0.10",
77
76
  "tslib": "^2.8.1"
78
77
  },
79
- "gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867"
78
+ "gitHead": "b7f1b4eafb760431e03955499d8eac9489438219"
80
79
  }