How to use @turf/area - 10 common examples

To help you get started, we’ve selected a few @turf/area 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 w3reality / three-geo / src / index.js View on Github external
// console.log(currentElevation, feats.length, feats);
                // feats.forEach(feat => { console.log('type:', feat.geometry.type); }); // 'Polygon'

                let mergedElevationPoly = feats.reduce(((accm, feat) => turfUnion(accm, feat)), feats[0]);
                // console.log('@@@', mergedElevationPoly, currentElevation);

                if (0) { // trim to desired search area
                    mergedElevationPoly = turfIntersect( // use module version instead
                        polygon, mergedElevationPoly);
                    // console.log('@@@', polygon);
                }

                // console.log('@@@mergedElevationPoly:', mergedElevationPoly);
                if (mergedElevationPoly) {
                    // console.log('@@@merge success', currentElevation);
                    let contourArea = turfArea(mergedElevationPoly.geometry);
                    // L.mapbox.featureLayer().setGeoJSON(mergedElevationPoly).addTo(map);

                    contours.push({
                        'geometry': mergedElevationPoly,
                        'ele': currentElevation,
                        'area': contourArea,
                    });
                }
            } catch (error) { // on merge fail, insert the previous contour again and skip
                console.log('merge failed at elevation '+currentElevation);
                console.log(error.message);
            }
        }

        // remove contour undercuts
        if (0) {
github CityOfPhiladelphia / mapboard / src / controller / data-manager.js View on Github external
let turfCoordinates = []
      for (let coordinate of featureSorted.geometry.coordinates[0]) {
        // console.log('coordinate:', coordinate);
        turfCoordinates.push(point(coordinate));
      }

      let distances = []
      for (let i=0; i
github Turfjs / turf / packages / turf-isobands / index.js View on Github external
ringsCoords.forEach(function (coords) {
        // var poly = polygon([points]);
        var ringArea = area(polygon([coords]));
        // create an array of areas value
        areas.push(ringArea);
        // associate each lineRing with its area
        ringsWithArea.push({ring: coords, area: ringArea});
    });
    areas.sort(function (a, b) { // bigger --> smaller
github developmentseed / observe / app / screens / OfflineMaps / OfflineAreaList.js View on Github external
createOfflineResource = async () => {
    const { fetchOfflineResources, navigation, setNotification, visibleBounds } = this.props

    if (visibleBounds == null) {
      // no bounds were selected
      return
    }

    const aoi = [
      visibleBounds[1][0],
      visibleBounds[1][1],
      visibleBounds[0][0],
      visibleBounds[0][1]
    ]

    const areaSqKm = area(bboxPolygon(aoi)) / (1000 ** 2)

    if (areaSqKm > 400) {
      setNotification({
        level: 'error',
        message: `${areaSqKm.toLocaleString()} km² is too large to download.`
      })

      return
    }

    navigation.navigate('OfflineAreaList')

    const name = (await getPlaceName(aoi)) || 'Unnamed Area'
    fetchOfflineResources(name, aoi)
  }
github PieceMaker / max-inscribed-circle / utils / geojson-utils.js View on Github external
// ---------------------------------------------------------------------------------------------------------------------
// GeoJSONUtils
//
// @module
// ---------------------------------------------------------------------------------------------------------------------

const area = require('@turf/area').default;
const _ = require('lodash');

// ---------------------------------------------------------------------------------------------------------------------

class GeoJSONUtils {
    constructor() {
    }

    /**
     * Checks to see if the feature is a Polygon formatted as a MultiPolygon.
     *
     * @param {Polygon} polygon
     * @returns {Polygon}
     */
    fixMultiPoly(polygon) {
        if(polygon.geometry.type === 'MultiPolygon' && polygon.geometry.coordinates[0].length === 1) {
github GlobalFishingWatch / map-client / app / src / _map / glmap / interaction.actions.js View on Github external
const getAreaKm2 = (glFeature) => {
  const areakm2 = (10 ** -6) * area(glFeature.geometry);
  const formatted = areakm2.toLocaleString('en-US', { maximumFractionDigits: 0 });
  return formatted;
};
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-nearest-neighbor-analysis / index.js View on Github external
var properties = options.properties || {};
    var units = options.units || 'kilometers';

    var features = [];
    featureEach(dataset, function (feature) {
        features.push(centroid(feature));
    });
    var n = features.length;
    var observedMeanDistance = features.map(function (feature, index) {
        var otherFeatures = featureCollection(features.filter(function (f, i) {
            return i !== index;
        }));
        return distance(feature, nearestPoint(feature, otherFeatures), {units: units});
    }).reduce(function (sum, value) { return sum + value; }, 0) / n;

    var populationDensity = n / convertArea(area(studyArea), 'meters', units);
    var expectedMeanDistance = 1 / (2 * Math.sqrt(populationDensity));
    var variance = 0.26136 / (Math.sqrt(n * populationDensity));
    studyArea.properties = properties;
    studyArea.properties.nearestNeighborAnalysis = {
        units: units,
        arealUnits: units + '²',
        observedMeanDistance: observedMeanDistance,
        expectedMeanDistance: expectedMeanDistance,
        nearestNeighborIndex: observedMeanDistance / expectedMeanDistance,
        numberOfPoints: n,
        zScore: (observedMeanDistance - expectedMeanDistance) / variance
    };

    return studyArea;
}
github GlobalFishingWatch / map-client / app / src / _map / glmap / interaction.actions.js View on Github external
const getAreaKm2 = (glFeature) => {
  const areakm2 = (10 ** -6) * area(glFeature.geometry);
  const formatted = areakm2.toLocaleString('en-US', { maximumFractionDigits: 0 });
  return formatted;
};
github hotosm / imagery-coordination / app / assets / scripts / components / task-size-warning.js View on Github external
(taskGeojson) => {
    let taskArea = 0;
    if (taskGeojson) {
      taskArea = area(taskGeojson);
    }
    return taskArea;
  });

@turf/area

turf area module

MIT
Latest version published 3 months ago

Package Health Score

98 / 100
Full package analysis

Popular @turf/area functions