James Beard e7227f51b7
Preliminary improvements to documentation, esp internal types e.g. Units (#2727)
* Added JSDoc for internal types and constants e.g. Unts and earthRadius. Minimal other changes to bring JSDoc types into line with code types. Added GeoJsonProperties to documentation.yml for type linking.

* Generated README.md files based on updated source that now includes JSDoc for internal types and constants e.g. Units. Also synced up some out of data JSDoc types with what is in the code.

* Switched the structure of documentation.yml to be more traditionally nested. We'll use this new structure from the turf-www repo to generate the website documentation in a more robust manner.

* For some reason leaving this function documented as the default (geojsonRbush) causes @turf/turf last-checks to fail. Specifically defining it as rbush like it used to be, except with the @function tag rather than @name.
2024-10-11 12:56:42 +11:00

45 lines
1.4 KiB
TypeScript

import { coordEach, featureEach } from "@turf/meta";
import { point, featureCollection } from "@turf/helpers";
import type { AllGeoJSON } from "@turf/helpers";
import type { Feature, FeatureCollection, Point } from "geojson";
/**
* Takes a feature or set of features and returns all positions as {@link Point|points}.
*
* @function
* @param {GeoJSON} geojson input features
* @returns {FeatureCollection<point>} points representing the exploded input features
* @throws {Error} if it encounters an unknown geometry type
* @example
* var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
*
* var explode = turf.explode(polygon);
*
* //addToMap
* var addToMap = [polygon, explode]
*/
function explode(geojson: AllGeoJSON): FeatureCollection<Point> {
const points: Feature<Point>[] = [];
if (geojson.type === "FeatureCollection") {
featureEach(geojson, function (feature) {
coordEach(feature, function (coord) {
points.push(point(coord, feature.properties));
});
});
} else if (geojson.type === "Feature") {
coordEach(geojson, function (coord) {
points.push(point(coord, geojson.properties));
});
} else {
// No properties to copy.
coordEach(geojson, function (coord) {
points.push(point(coord));
});
}
return featureCollection(points);
}
export { explode };
export default explode;