-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (43 loc) · 1.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var featureCollection = require('turf-featurecollection');
var each = require('turf-meta').coordEach;
var point = require('turf-point');
/**
* Takes a feature or set of features and returns all positions as
* {@link Point|points}.
*
* @module turf/explode
* @category misc
* @param {(Feature|FeatureCollection)} input input features
* @return {FeatureCollection<point>} points representing the exploded input features
* @throws {Error} if it encounters an unknown geometry type
* @example
* var poly = {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Polygon",
* "coordinates": [[
* [177.434692, -17.77517],
* [177.402076, -17.779093],
* [177.38079, -17.803937],
* [177.40242, -17.826164],
* [177.438468, -17.824857],
* [177.454948, -17.796746],
* [177.434692, -17.77517]
* ]]
* }
* };
*
* var points = turf.explode(poly);
*
* //=poly
*
* //=points
*/
module.exports = function(layer) {
var points = [];
each(layer, function(coord) {
points.push(point(coord));
});
return featureCollection(points);
};