zoukankan      html  css  js  c++  java
  • 基于 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));
        }
    

      

  • 相关阅读:
    在WPF中应用弱事件模式
    MSTest DeploymentItemAttribute
    delegate, event
    zookeeper 开机启动197
    centos 7 安装solr7.3.0 配置mysql197
    solr7.4 centos7安装197
    centos 查看mysql数据库命令197
    bootstrapValidator验证197
    idea快捷键197
    sun.misc.Unsafe.park(Native Method)197
  • 原文地址:https://www.cnblogs.com/hillgisman/p/6178541.html
Copyright © 2011-2022 走看看