• 基于 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));
        }
    

      

  • 相关阅读:
    学习H5一周随笔
    vue项目中vux的使用
    git操作常用命令
    vue2.0 实现全选和全不选
    鼠标事件以及clientX、offsetX、screenX、pageX、x的区别
    js编写当天简单日历
    UIView.frame的骗局
    设计模式笔记感悟
    实用图像处理入门
    实用图像处理入门
  • 原文地址:https://www.cnblogs.com/hillgisman/p/6178541.html
Copyright © 2020-2023  润新知