How to use the @turf/turf.polygon 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 grasslandnetwork / node_lite / gui / app.js View on Github external
// top_right = { "lat": positionAndBearing[0].lat + tr_lat_displacement, "lng": positionAndBearing[0].lng + tr_lng_displacement };
		// bottom_right = { "lat": positionAndBearing[0].lat + br_lat_displacement, "lng": positionAndBearing[0].lng + br_lng_displacement };
		// bottom_left = { "lat": positionAndBearing[0].lat + bl_lat_displacement, "lng": positionAndBearing[0].lng + bl_lng_displacement };
		// top_left = { "lat": positionAndBearing[0].lat + tl_lat_displacement, "lng": positionAndBearing[0].lng + tl_lng_displacement };


		top_right = [ positionAndBearing[0].lng + (this.defaultFootprint[category].lng_dst/2), positionAndBearing[0].lat + (this.defaultFootprint[category].lat_dst/2) ];

		bottom_right = [ positionAndBearing[0].lng + (this.defaultFootprint[category].lng_dst/2), positionAndBearing[0].lat - (this.defaultFootprint[category].lat_dst/2) ];

		bottom_left = [ positionAndBearing[0].lng - (this.defaultFootprint[category].lng_dst/2), positionAndBearing[0].lat - (this.defaultFootprint[category].lat_dst/2) ];

		top_left = [ positionAndBearing[0].lng - (this.defaultFootprint[category].lng_dst/2), positionAndBearing[0].lat + (this.defaultFootprint[category].lat_dst/2) ];
		
		
		var poly = turfPolygon(
			[
				[
					top_right,
					bottom_right,
					bottom_left,
					top_left,
					top_right
				]
			]
		);

		// console.log(positionAndBearing[1]);

		var rotatedPoly = turfTransformRotate(poly, positionAndBearing[1]);

		if (DEMO_MODE) {
github Googer / Professor-Pine / app / region.js View on Github external
getPolygonFromRegion(region) {
    const coords = [];
    for (let p = 0; p < region.length; p++) {
      let point = region.points[p];
      const points = [point.y, point.x];
      coords.push(points);
    }

    try {
      return turf.polygon([coords]);
    } catch (error) {
      log.error(error);
      return null;
    }
  }
github nasa-gibs / worldview / web / js / map / measure / util.js View on Github external
export function getRhumbLineArea(polygon, projection) {
  let transformedPoly = polygon;
  if (projection !== referenceProjection) {
    transformedPoly = polygon.clone().transform(projection, referenceProjection);
  }
  const coords = polygon.getCoordinates()[0];
  if (coords.length < 4) {
    return 0;
  }
  const poly = TurfPolygon(transformedPoly.getCoordinates());
  return TurfArea(poly);
}
github code4history / Maplat / editor / lib / mapedit.js View on Github external
var cwCheck = isClockwise(coordinates);
    if (cwCheck) coordinates = ['a', 'c', 'b', 'a'].map(function(key) {
        return tri.properties[key].geom;
    });
    var geoms = tri.geometry.coordinates[0];
    var props = tri.properties;
    var properties = !cwCheck ? {
        a: {geom: geoms[0], index: props['a'].index},
        b: {geom: geoms[1], index: props['b'].index},
        c: {geom: geoms[2], index: props['c'].index}
    } : {
        a: {geom: geoms[0], index: props['a'].index},
        b: {geom: geoms[2], index: props['c'].index},
        c: {geom: geoms[1], index: props['b'].index}
    };
    return turf.polygon([coordinates], properties);
}
github Googer / Professor-Pine / app / map.js View on Github external
            .map(coordinates => turf.polygon(coordinates))
            .forEach(polygon => {
github hotosm / tasking-manager / frontend / src / components / projectCreate / setTaskSizes.js View on Github external
taskGrid.features.forEach(f => {
    let poly = turf.polygon(f.geometry.coordinates[0]);
    let contains = turf.intersect(geom, poly);
    if (contains === null) {
      newTaskGrid.push(f);
    } else {
      const splitGrid = makeGrid(f, f.properties.zoom + 1, {});
      splitGrid.features.forEach(g => {
        newTaskGrid.push(g);
      });
    }
  });
github Googer / Professor-Pine / app / region.js View on Github external
enlargePolygonFromRegion(region) {
    const coords = [];
    for (let p = 0; p < region.length; p++) {
      let point = region.points[p];
      const points = [point.y, point.x];
      coords.push(points);
    }

    try {
      const poly = turf.polygon([coords]);
      const buffer = turf.transformScale(poly, 1.5);

      return this.regionFromGeoJSON(buffer);
    } catch (error) {
      log.error(error);
      return null;
    }
  }