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

Posted 帕洛马山

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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));
    }

  

以上是关于geojson数据类型面转线Transforms Polygons and MultiPolygons to LineStrings.的主要内容,如果未能解决你的问题,请参考以下文章

小议ArcMap面转线的几种方式

arcmap怎么把闭合的线构成面啊?

GIS面转CAD填充方法1——QGIS

torchvision找不到transforms

将 geoJson 数据转换为 sql server 空间数据类型(GIS)

将 JSON 转换为 QGIS GeoJSON:同时具有多种功能和不同类型