-1

I have an leaflet map where the users draw a polygon, and this polygon gave me lat and long points.

I'm using react js too.

polygon draw

i would like to know the polygon area so that i can take the id from the black dots that are within the polygon area. So the question is:

how do I remove the area of ​​my polygon according to the information generated from it?

values from polygon drawn

polygon draw function


        if (type === 'Polygon') {
          console.log(layer);
          var geojson = layer.toGeoJSON();
          console.log(geojson);
        }
  • As noted in https://gis.stackexchange.com/questions/383547/picking-up-the-coordinates-inside-this-polygon-draw , use turfjs to perform point-in-polygon queries. Asking the same thing with different words is not gonna help, consider editing the question instead. – IvanSanchez Jan 11 '21 at 23:48
  • its not the same thing i'm asking here...i wanna to have the area from a polygon – Rayssa Rocha Jan 12 '21 at 00:17

1 Answers1

1

I'm assuming that finding the area of a polygon would resolve your problem. To find an area of the polygon, try using the shoelace algorithm. Learn more about how the algorithm works here

// shoelace algorithm
function polygonArea(coordinates) {
    var sum = 0.0;
    var length = coordinates.length;
    if (length < 3) {
        return sum;
    }
    coordinates.forEach(function (d1, i1) {
        var i2 = (i1 + 1) % length;
        var d2 = coordinates[i2];
        sum += (d2[1] * d1[0]) - (d1[1] * d2[0]);
    });
    return sum / 2;
}
Parzival
  • 2,051
  • 4
  • 14
  • 32