geojson数据类型面转线Transforms Polygons and MultiPolygons to LineStrings.
function flatten(array) { return [].concat.apply([], array); } function polygonToLineString(coordinates, properties) { return coordinates.map(function(coordinates) { return turf.lineString(coordinates, properties); }); } function multiPolygonToLineString(coordinates, properties) { return flatten(coordinates.map(function(coordinates) { return polygonToLineString(coordinates, properties); })); } function toLineString(feature) { var geometry = feature.geometry, properties = feature.properties; switch (geometry.type) { case ‘Polygon‘: return polygonToLineString(geometry.coordinates, properties); case ‘MultiPolygon‘: return multiPolygonToLineString(geometry.coordinates, properties); default: return feature; } } /** * Transforms Polygons and MultiPolygons to LineStrings. * * @module turf/polygonToLine * @category transformation * @param {Object} geojson any GeoJSON object * @returns {Object} FeatureCollection where * Polygons and MultiPolygons transformed to LineStrings. */ function polygon2line(geojson) { var features = geojson.features.map(toLineString); return turf.featureCollection(flatten(features)); }
文章来自:http://www.cnblogs.com/hillgisman/p/6178541.html