How to use the turf.area function in turf

To help you get started, we’ve selected a few 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 hotosm / osm-analytics / app / components / Map / index.js View on Github external
if (isEditable) {
        boundsLayer.enableEdit()
      }

      // set map view to region
      try { // geometry calculcation are a bit hairy for invalid geometries (which may happen during polygon editing)
        let viewPort = bboxPolygon(map.getBounds().toBBoxString().split(',').map(Number))
        let xorAreaViewPort = erase(viewPort, L.polygon(boundsLayer.getLatLngs()[1]).toGeoJSON())
        let fitboundsFunc
        if (moveDirectly) {
          fitboundsFunc = ::map.fitBounds
          moveDirectly = false
        } else if (
          !xorAreaViewPort // new region fully includes viewport
          || area(xorAreaViewPort) > area(viewPort)*(1-0.01) // region is small compared to current viewport (<10% of the area covered) or feature is outside current viewport
        ) {
          fitboundsFunc = ::map.flyToBounds
        } else {
          fitboundsFunc = () => {}
        }
        fitboundsFunc(
          // zoom to inner ring!
          boundsLayer.getLatLngs().slice(1)
            .map(coords => L.polygon(coords).getBounds())
            .reduce((bounds1, bounds2) => bounds1.extend(bounds2)),
        {
          paddingTopLeft: [20, 10+52],
          paddingBottomRight: [20, 10+ ((fitBoundsWithBottomPadding) ? 212 : 52)]
        })
      } catch(e) {}
    });
github funkeinteraktiv / cogran / lib / methods / attribute-weighting-advanced.js View on Github external
intersects.forEach((d,i) => {
    const At = Turf.area(feature);
    const Ast = Turf.area(d);
    const Qt = feature.properties[options.weight];
    const Qst = (Ast / At) * Qt;

    const attributeValue = parseFloat(sourceFeatures[i].properties[options.attr]);

    // wenn komplett im source feature,
    const sb = Turf.extent(sourceFeatures[i]);
    let isInside = true;
    if(!Turf.inside(Turf.point([sb[0], sb[1]]), d)) { isInside = false };
    if(!Turf.inside(Turf.point([sb[2], sb[3]]), d)) { isInside = false };

    if(isInside) {
      if(!isNaN(attributeValue)) {
        result += Ps;
      }
      return;
github funkeinteraktiv / cogran / lib / methods / binary-dasymetric-mapping-relative.js View on Github external
intersects.forEach((d,i) => {
      const Atsp2 = Turf.area(d);
      const Gg = sourceFeatures[i].properties['Aggr'];
      const Ps = Gg * ((sourceFeatures[i].properties['Relative']) / 100);
      const Asp2 = d.properties.parentArea;

      // const Asp2 = Turf.area(Asp.features[i]);
      // const Ps = sourceFeatures[i].properties[options.attr];
      // const As = Turf.area(sourceFeatures[i]);

      result += (Atsp2 * Ps) / Asp2;
    });
github mapbox / mapping / utilities / metrics / area.js View on Github external
cities.features.forEach(function (item) {
  console.log(item.properties.label + ',' + turf.area(item) / 1000000)
})
github funkeinteraktiv / cogran / lib / methods / n-class-dasymetric-weighting-relative.js View on Github external
function dropTinyAreas(features){
	var new_fc = new Array();
	var count = 0;
	
	for (var i=0; i< features.length; i++){
		if (Turf.area(features[i]) > 10) {
			new_fc.push(features[i]);
		}
		else {
			count = count +1;
			console.log('Dropping Tiny Feature.');
		}
	}
	
	console.log("Dropping feature with tiny area: " + count +'/' + features.length); 
	return new_fc;	
}
github funkeinteraktiv / cogran / lib / methods / n-class-dasymetric-weighting.js View on Github external
function intersectSourceMask(a, b) {

  const resultFeatures = [];

  for(let i = 0; i < a.features.length; i++) {
    Logger.info(`[nClassDasymetricWeighting][intersectSourceMask][${i}/${a.features.length}]`);

    for(let j = 0; j < b.features.length; j++) {
      const d = a.features[i];
      const e = b.features[j];

      const isIntersect = Turf.intersect(d, e);

      if(isIntersect) {
        isIntersect.properties = objectAssign({}, d.properties, e.properties, { maskArea: Turf.area(e) });
        resultFeatures.push(isIntersect);
      }
    }
  }

  return Turf.featurecollection(resultFeatures);
}
github funkeinteraktiv / cogran / lib / methods / n-class-dasymetric-weighting-relative.js View on Github external
b.features.forEach(e => {
		
      let isIntersect = Turf.intersect(d, e);

      if(isIntersect && Turf.area(isIntersect) > 0) {
		isIntersect = arealizeGeometryCollection(isIntersect);
        isIntersect.properties = objectAssign({}, d.properties, e.properties)
        resultFeatures.push(isIntersect);
      }
	  
    });
  });
github funkeinteraktiv / cogran / lib / methods / n-class-dasymetric-weighting-relative.js View on Github external
function intersectSourceMask(a, b) {

  const resultFeatures = [];

  for(let i = 0; i < a.features.length; i++) {
    Logger.info(`[nClassDasymetricWeightingRelative][intersectSourceMask][${i}/${a.features.length}]`);

    for(let j = 0; j < b.features.length; j++) {
      const d = a.features[i];
      const e = b.features[j];

      let isIntersect = Turf.intersect(d, e);

      if(isIntersect) {
		isIntersect = arealizeGeometryCollection(isIntersect);
        isIntersect.properties = objectAssign({}, d.properties, e.properties, { maskArea: Turf.area(e) });
        resultFeatures.push(isIntersect);
      }
    }
  }

  return Turf.featurecollection(resultFeatures);
}