How to use the @turf/meta.lineReduce function in @turf/meta

To help you get started, we’ve selected a few @turf/meta 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-line-dissolve.ts View on Github external
options: {mutate?: boolean} = {},
): Feature | null {
    // Optional parameters
    options = options || {};
    if (!isObject(options)) { throw new Error("options is invalid"); }
    const mutate = options.mutate;

    // Validation
    if (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(geojson); }

    const result: any[] = [];
    const lastLine = lineReduce(geojson, (previousLine: any, currentLine: any) => {
        // Attempt to merge this LineString with the other LineStrings, updating
        // the reference as it is merged with others and grows.
        const 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;
        }
    });
    // Append the last line
    if (lastLine) { result.push(lastLine); }

    // Return null if no lines were dissolved
github Turfjs / turf / packages / turf-concave / lib / turf-line-dissolve.ts View on Github external
options: {mutate?: boolean} = {},
): Feature | null {
    // Optional parameters
    options = options || {};
    if (!isObject(options)) { throw new Error("options is invalid"); }
    const mutate = options.mutate;

    // Validation
    if (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(geojson); }

    const result: any[] = [];
    const lastLine = lineReduce(geojson, (previousLine: any, currentLine: any) => {
        // Attempt to merge this LineString with the other LineStrings, updating
        // the reference as it is merged with others and grows.
        const 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;
        }
    });
    // Append the last line
    if (lastLine) { result.push(lastLine); }

    // Return null if no lines were dissolved
github Turfjs / turf / src / concave / lib / turf-line-dissolve.js View on Github external
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;
        }
    });
    // Append the last line
    if (lastLine) {
        result.push(lastLine);