How to use the @turf/meta.flattenEach 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 / packages / turf-mask / index.js View on Github external
function unionPolygons(polygons) {
    if (polygons.features.length <= 1) return polygons;

    var tree = createIndex(polygons);
    var results = [];
    var removed = {};

    flattenEach(polygons, function (currentFeature, currentIndex) {
        // Exclude any removed features
        if (removed[currentIndex]) return true;

        // Don't search for itself
        tree.remove({index: currentIndex}, filterByIndex);
        removed[currentIndex] = true;

        // Keep applying the union operation until no more overlapping features
        while (true) {
            var bbox = turfBBox(currentFeature);
            var search = tree.search({
                minX: bbox[0],
                minY: bbox[1],
                maxX: bbox[2],
                maxY: bbox[3]
            });
github Turfjs / turf / src / concave / lib / turf-polygon-dissolve.ts View on Github external
export default function polygonDissolve(
    geojson: FeatureCollection,
    options: {mutate?: boolean} = {},
): Feature | null {
    // 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
    // Topojson modifies in place, so we need to deep clone first
    if (options.mutate === false || options.mutate === undefined) { geojson = clone(geojson); }

    const geoms: any[] = [];
    flattenEach(geojson, (feature) => {
        geoms.push(feature.geometry);
    });
    const topo: any = topology({geoms: geometryCollection(geoms).geometry});
    const merged: any = merge(topo, topo.objects.geoms.geometries);
    return merged;
}
github Turfjs / turf / packages / turf-polygonize / lib / Graph.js View on Github external
static fromGeoJson(geoJson) {
        validateGeoJson(geoJson);

        const graph = new Graph();
        flattenEach(geoJson, feature => {
            featureOf(feature, 'LineString', 'Graph::fromGeoJson');
            // When a LineString if formed by many segments, split them
            coordReduce(feature, (prev, cur) => {
                if (prev) {
                    const start = graph.getNode(prev),
                        end = graph.getNode(cur);

                    graph.addEdge(start, end);
                }
                return cur;
            });
        });

        return graph;
    }
github Turfjs / turf / packages / turf-boolean-intersects / index.ts View on Github external
flattenEach(feature1, (flatten1) => {
        flattenEach(feature2, (flatten2) => {
            if (bool === true) { return true; }
            bool = !booleanDisjoint(flatten1.geometry, flatten2.geometry);
        });
    });
    return bool;
github Turfjs / turf / packages / turf-difference / index.js View on Github external
function removeEmptyPolygon(geom) {
    switch (geom.type) {
    case 'Polygon':
        if (area(geom) > 1) return geom;
        return null;
    case 'MultiPolygon':
        var coordinates = [];
        flattenEach(geom, function (feature) {
            if (area(feature) > 1) coordinates.push(feature.geometry.coordinates);
        });
        if (coordinates.length) return {type: 'MultiPolygon', coordinates: coordinates};
    }
}
github Turfjs / turf / packages / turf-mask / index.js View on Github external
function buildMask(maskPolygon, polygonOuters, polygonInners) {
    var coordinates = [];
    coordinates.push(maskPolygon.geometry.coordinates[0]);

    flattenEach(polygonOuters, function (feature) {
        coordinates.push(feature.geometry.coordinates[0]);
    });

    flattenEach(polygonInners, function (feature) {
        coordinates.push(feature.geometry.coordinates[0]);
    });
    return polygon(coordinates);
}
github Turfjs / turf / packages / turf-mask / index.js View on Github external
function buildMask(maskPolygon, polygonOuters, polygonInners) {
    var coordinates = [];
    coordinates.push(maskPolygon.geometry.coordinates[0]);

    flattenEach(polygonOuters, function (feature) {
        coordinates.push(feature.geometry.coordinates[0]);
    });

    flattenEach(polygonInners, function (feature) {
        coordinates.push(feature.geometry.coordinates[0]);
    });
    return polygon(coordinates);
}
github Turfjs / turf / packages / turf-boolean-disjoint / index.ts View on Github external
function booleanDisjoint(feature1: Feature | Geometry, feature2: Feature | Geometry): boolean {
    let bool = true;
    flattenEach(feature1, (flatten1) => {
        flattenEach(feature2, (flatten2) => {
            if (bool === false) { return false; }
            bool = disjoint(flatten1.geometry, flatten2.geometry);
        });
    });
    return bool;
}