How to use the @turf/meta.propReduce 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-kernel_density / index.js View on Github external
w = isWeighted ? (current.properties[weight] || 0) : 1,
                        c = getCoord(current).map((a, i) => Math.pow(w * a - m[i], 2));
                    return prev.map((a, i) => a + c[i]);
                }, [0, 0]),
                degDist = Math.sqrt((_sum[0] + _sum[1]) / pointsCount);
            return radiansToLength(degreesToRadians(degDist), 'kilometers') / latCorrection;
        };

    // find collection's centroid
    if (weight === undefined || weight.length === 0) {
        mc = centroid(output, {
            'weight': null
        });
    } else {
        let
            mw = propReduce(output, (prev, current) => prev + current[weight] * 1, 0),
            _weighted = featureReduce(output, (prev, current) => {
                const
                    w = current.properties[weight],
                    c = getCoord(current).map(a => a * w / mw);
                return prev.map((a, i) => a + c[i]);
            }, [0, 0]);
        mc = point(_weighted, {
            'weight': mw
        });
    }
    // calc the median distance from the centroid to each point (km)
    dists = featureReduce(output, (prev, current) => {
        prev.push(distance(current, mc));
    }, []);
    median = _getMedian(dists);
    // calc the standard distance (pseudo-km)