-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
30 lines (28 loc) · 1.01 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
var flatten = require('geojson-flatten');
var featurecollection = require('turf-featurecollection');
/**
* flattens any {@link GeoJSON} to a {@link FeatureCollection} using [geojson-flatten](https://github.com/mapbox/geojson-flatten).
*
* @module turf/flatten
* @category misc
* @param {geojson} input any valid {@link GeoJSON} with multi-geometry {@link Feature}s
* @return {flattened} a flattened {@link FeatureCollection}
* @example
* var geometry = {
* "type": "MultiPolygon",
* "coordinates": [
* [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
* [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
* [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
* ]
* };
*
* var flattened = turf.flatten(geometry);
*
* //=flattened
*/
module.exports = function (geojson) {
var flattened = flatten(geojson);
if(flattened.type === 'FeatureCollection') return flattened;
else return featurecollection(flatten(geojson));
};