How to use the @turf/turf.area function in @turf/turf

To help you get started, we’ve selected a few @turf/turf 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 DoFabien / OsmGo / src / services / osmApi.service.ts View on Github external
private wayToPoint(FeatureCollection) {
        let features = FeatureCollection.features;
        for (let i = 0; i < features.length; i++) {

            let feature = features[i];
            // console.log(feature);
            if (feature.geometry) {
                if (feature.geometry.type !== 'Point') {

                    // on stocke la géométrie d'origine dans .way_geometry
                    feature.properties.way_geometry = JSON.parse(JSON.stringify(feature.geometry));
                    let geom;
                    switch (feature.geometry.type) {
                        case 'Polygon':
                            feature.properties['mesure'] = area(feature.geometry)
                            geom = polygon(feature.geometry.coordinates);
                            break;
                        case 'MultiPolygon':
                            feature.properties['mesure'] = area(feature.geometry)
                            geom = multiPolygon(feature.geometry.coordinates);
                            break;
                        case 'LineString':
                            feature.properties['mesure'] = length(feature.geometry)
                            geom = lineString(feature.geometry.coordinates);
                            break;
                        case 'MultiLineString':
                            feature.properties['mesure'] = length(feature.geometry)
                            geom = multiLineString(feature.geometry.coordinates);
                            break;
                    }
github w3reality / three-laser-pointer / examples / demo-path / src / index.js View on Github external
//========
                // - turf.merge is deprecated, so...
                // - https://github.com/turf-junkyard/turf-merge
                //     This module is now deprecated in favor of using
                //     the turf-union module repeatedly on an array.
                // - https://gis.stackexchange.com/questions/243460/turf-js-union-with-array-of-features
                // console.log('feat collection:', turf.featureCollection(elevationPolys));
                let mergedElevationPoly = turf.union.apply(
                    this, turf.featureCollection(elevationPolys).features);

                // trim to desired search area
                mergedElevationPoly = turf.intersect(
                    polygon, mergedElevationPoly);

                if (mergedElevationPoly) {
                    let contourArea = turf.area(mergedElevationPoly.geometry);
                    // FIXME: ???????? ???????? ???????? ????????
                    // 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
github Googer / Professor-Pine / app / map.js View on Github external
      .sort((matchA, matchB) => turf.area(matchB.intersection) - turf.area(matchA.intersection))
      .map(({region, intersection}) => region.properties.name);
github heremaps / here-cli / src / here-xyz.ts View on Github external
function populateArea(feature: any){
    let area = turf.area(feature);
    if(!feature.properties){
        feature.properties = {};
    }
    feature.properties['xyz_area_sqm'] = area;
    feature.properties['xyz_area_sqkm'] = (area / 1000000).toFixed(2);
    feature.properties['xyz_area_sqmiles'] = (area * 0.00000038610215855).toFixed(2);
    return feature; 
}
github Googer / Professor-Pine / app / map.js View on Github external
        results.sort((a, b) => turf.area(b) - turf.area(a));
      }
github hotosm / tasking-manager / frontend / src / components / projectCreate / setAOI.js View on Github external
const setDataGeom = geom => {
    const area = turf.area(geom) / 1e6;
    const zoomLevel = mapObj.map.getZoom() + 4;
    const grid = makeGrid(geom, zoomLevel, {});
    mapObj.map.fitBounds(turf.bbox(geom), { padding: 20 });
    updateMetadata({
      ...metadata,
      geom: geom,
      area: area.toFixed(2),
      zoomLevel: zoomLevel,
      taskGrid: grid,
      tempTaskGrid: grid,
    });

    if (mapObj.map.getLayer(layer_name)) {
      mapObj.map.removeLayer(layer_name);
    }
    if (mapObj.map.getSource(layer_name)) {
github osmlab / osmlint / validators / duplicateBuilding / map.js View on Github external
var buildingTraceTree = rbush(bboxes.length);
  buildingTraceTree.load(bboxes);
  for (var j = 0; j < bboxes.length; j++) {
    var bbox = bboxes[j];
    var buildingA = buildings[bbox.id];
    var areabuildingA = turf.area(buildingA);
    var overlaps = buildingTraceTree.search(bbox);
    for (var k = 0; k < overlaps.length; k++) {
      var overlap = overlaps[k];
      var buildingB = buildings[overlap.id];
      if (overlap.id !== bbox.id) {
        var difference = turf.difference(
          buildingA, buildingB
        );
        //detecting buildings that have > 90% overlap
        if (difference && (areabuildingA - turf.area(difference)) > (areabuildingA * 0.9)) {
          var points = turf.explode(buildingA);
          var multiPoint = turf.combine(points).features[0];
          multiPoint.properties = {
            _fromWay: buildingA.properties['@id'],
            _toWay: buildingB.properties['@id'],
            _osmlint: osmlint
          };
          //save detection
          output[overlap.id] = buildingA;
          output[bbox.id] = buildingB;
          output[overlap.id + bbox.id + 'M'] = multiPoint;
        }
      }
    }
  }