码迷,mamicode.com
首页 > Web开发 > 详细

geojson数据类型面转线Transforms Polygons and MultiPolygons to LineStrings.

时间:2016-12-14 11:42:48      阅读:1278      评论:0      收藏:0      [点我收藏+]

标签:script   and   category   cat   mat   apply   app   rip   ons   

    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));
    }

  

geojson数据类型面转线Transforms Polygons and MultiPolygons to LineStrings.

标签:script   and   category   cat   mat   apply   app   rip   ons   

原文地址:http://www.cnblogs.com/hillgisman/p/6178541.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!