How to use the @turf/clone.default function in @turf/clone

To help you get started, we’ve selected a few @turf/clone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Turfjs / turf / src / concave / lib / turf-polygon-dissolve.js View on Github external
function polygonDissolve(geojson, options) {
    if (options === void 0) { options = {}; }
    // Validation
    if (invariant_1.getType(geojson) !== "FeatureCollection") {
        throw new Error("geojson must be a FeatureCollection");
    }
    if (!geojson.features.length) {
        throw new Error("geojson is empty");
    }
    // Clone geojson to avoid side effects
    // Topojson modifies in place, so we need to deep clone first
    if (options.mutate === false || options.mutate === undefined) {
        geojson = clone_1.default(geojson);
    }
    var geoms = [];
    meta_1.flattenEach(geojson, function (feature) {
        geoms.push(feature.geometry);
    });
    var topo = topojson_1.topology({ geoms: helpers_1.geometryCollection(geoms).geometry });
    var merged = topojson_1.merge(topo, topo.objects.geoms.geometries);
    return merged;
}
exports.default = polygonDissolve;
github Turfjs / turf / src / concave / lib / turf-line-dissolve.js View on Github external
// Optional parameters
    options = options || {};
    if (!helpers_1.isObject(options)) {
        throw new Error("options is invalid");
    }
    var mutate = options.mutate;
    // Validation
    if (invariant_1.getType(geojson) !== "FeatureCollection") {
        throw new Error("geojson must be a FeatureCollection");
    }
    if (!geojson.features.length) {
        throw new Error("geojson is empty");
    }
    // Clone geojson to avoid side effects
    if (mutate === false || mutate === undefined) {
        geojson = clone_1.default(geojson);
    }
    var result = [];
    var lastLine = meta_1.lineReduce(geojson, function (previousLine, currentLine) {
        // Attempt to merge this LineString with the other LineStrings, updating
        // the reference as it is merged with others and grows.
        var merged = mergeLineStrings(previousLine, currentLine);
        // Accumulate the merged LineString
        if (merged) {
            return merged;
            // Put the unmerged LineString back into the list
        }
        else {
            result.push(previousLine);
            return currentLine;
        }
    });
github Turfjs / turf / src / concave / lib / turf-dissolve.js View on Github external
options = options || {};
    if (!helpers_1.isObject(options)) {
        throw new Error("options is invalid");
    }
    var mutate = options.mutate;
    // Validation
    if (invariant_1.getType(geojson) !== "FeatureCollection") {
        throw new Error("geojson must be a FeatureCollection");
    }
    if (!geojson.features.length) {
        throw new Error("geojson is empty");
    }
    // Clone geojson to avoid side effects
    // Topojson modifies in place, so we need to deep clone first
    if (mutate === false || mutate === undefined) {
        geojson = clone_1.default(geojson);
    }
    // Assert homogenity
    var type = getHomogenousType(geojson);
    if (!type) {
        throw new Error("geojson must be homogenous");
    }
    // Data => Typescript hack
    var data = geojson;
    switch (type) {
        case "LineString":
            return turf_line_dissolve_1.default(data, options);
        case "Polygon":
            return turf_polygon_dissolve_1.default(data, options);
        default:
            throw new Error(type + " is not supported");
    }

@turf/clone

turf clone module

MIT
Latest version published 3 months ago

Package Health Score

98 / 100
Full package analysis

Popular @turf/clone functions