How to use the @turf/meta.geomEach 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-rewind / index.js View on Github external
function rewind(geojson, reverse) {
    var type = (geojson.type === 'Feature') ? geojson.geometry.type : geojson.type;

    // Support all GeoJSON Geometry Objects
    switch (type) {
    case 'GeometryCollection':
        geomEach(geojson, function (geometry) {
            rewind(geometry, reverse);
        });
        return geojson;
    case 'LineString':
        rewindLineString(getCoords(geojson), reverse);
        return geojson;
    case 'Polygon':
        rewindPolygon(getCoords(geojson), reverse);
        return geojson;
    case 'MultiLineString':
        getCoords(geojson).forEach(function (lineCoords) {
            rewindLineString(lineCoords, reverse);
        });
        return geojson;
    case 'MultiPolygon':
        getCoords(geojson).forEach(function (lineCoords) {
github Turfjs / turf / packages / turf-buffer / index.js View on Github external
if (!geojson) throw new Error('geojson is required');
    if (typeof options !== 'object') throw new Error('options must be an object');
    if (typeof steps !== 'number') throw new Error('steps must be an number');

    // Allow negative buffers ("erosion") or zero-sized buffers ("repair geometry")
    if (radius === undefined) throw new Error('radius is required');
    if (steps <= 0) throw new Error('steps must be greater than 0');

    // default params
    steps = steps || 64;
    units = units || 'kilometers';

    var results = [];
    switch (geojson.type) {
    case 'GeometryCollection':
        geomEach(geojson, function (geometry) {
            var buffered = bufferFeature(geometry, radius, units, steps);
            if (buffered) results.push(buffered);
        });
        return featureCollection(results);
    case 'FeatureCollection':
        featureEach(geojson, function (feature) {
            var multiBuffered = bufferFeature(feature, radius, units, steps);
            if (multiBuffered) {
                featureEach(multiBuffered, function (buffered) {
                    if (buffered) results.push(buffered);
                });
            }
        });
        return featureCollection(results);
    }
    return bufferFeature(geojson, radius, units, steps);
github Turfjs / turf / packages / turf-center-mean / index.ts View on Github external
function centerMean<p>(
    geojson: any, // To-Do include Typescript AllGeoJSON
    options: {properties?: P, bbox?: BBox, id?: Id, weight?: string} = {},
): Feature {
    let sumXs = 0;
    let sumYs = 0;
    let sumNs = 0;
    geomEach(geojson, function (geom, featureIndex, properties) {
        let weight = properties[options.weight];
        weight = (weight === undefined || weight === null) ? 1 : weight;
        if (!isNumber(weight)) throw new Error('weight value must be a number for feature index ' + featureIndex);
        weight = Number(weight);
        if (weight &gt; 0) {
            coordEach(geom, function (coord) {
                sumXs += coord[0] * weight;
                sumYs += coord[1] * weight;
                sumNs += weight;
            });
        }
    });
    return point([sumXs / sumNs, sumYs / sumNs], options.properties, options);
}
</p>
github Turfjs / turf / packages / turf-simplify / index.js View on Github external
function simplify(geojson, options) {
    // Optional parameters
    options = options || {};
    if (!isObject(options)) throw new Error('options is invalid');
    var tolerance = options.tolerance !== undefined ? options.tolerance : 1;
    var highQuality = options.highQuality || false;
    var mutate = options.mutate || false;

    if (!geojson) throw new Error('geojson is required');
    if (tolerance &amp;&amp; tolerance &lt; 0) throw new Error('invalid tolerance');

    // Clone geojson to avoid side effects
    if (mutate !== true) geojson = clone(geojson);

    geomEach(geojson, function (geom) {
        simplifyGeom(geom, tolerance, highQuality);
    });
    return geojson;
}
github Turfjs / turf / packages / turf-polygon-smooth / index.js View on Github external
function polygonSmooth(inputPolys, options) {
    var outPolys = [];
    // Optional parameters
    var iterations = options.iterations || 1;
    if (!inputPolys) throw new Error('inputPolys is required');

    geomEach(inputPolys, function (geom, geomIndex, properties) {
        var outCoords;
        var poly;
        var tempOutput;

        switch (geom.type) {
        case 'Polygon':
            outCoords = [[]];
            for (var i = 0; i &lt; iterations; i++) {
                tempOutput = [[]];
                poly = geom;
                if (i &gt; 0) poly = polygon(outCoords).geometry;
                processPolygon(poly, tempOutput);
                outCoords = tempOutput.slice(0);
            }
            outPolys.push(polygon(outCoords, properties));
            break;
github Turfjs / turf / packages / turf-points-within-polygon / index.js View on Github external
featureEach(points, function (point) {
        var contained = false;
        geomEach(polygons, function (polygon) {
            if (pointInPolygon(point, polygon)) contained = true;
        });
        if (contained) {
            results.push(point);
        }
    });
    return featureCollection(results);
github Turfjs / turf / packages / turf-nearest-point-to-line / index.ts View on Github external
function normalize(points: any): FeatureCollection {
    const features: any[] = [];
    const type = points.geometry ? points.geometry.type : points.type;
    switch (type) {
    case "GeometryCollection":
        geomEach(points, (geom) =&gt; {
            if (geom.type === "Point") { features.push({type: "Feature", properties: {}, geometry: geom}); }
        });
        return {type: "FeatureCollection", features};
    case "FeatureCollection":
        points.features = points.features.filter((feature: any) =&gt; {
            return feature.geometry.type === "Point";
        });
        return points;
    default:
        throw new Error("points must be a Point Collection");
    }
}