Area of Polygon #10

Closed
brunosan opened this Issue Jan 26, 2014 · 5 comments

Comments

Projects
None yet
3 participants
@brunosan

Add a micro plugin to show the Area of a Polygon when drawing.

This would be useful for e.g. agriculture purposes. Draw a shape and know how many acres that is. (area of a field, lake, ...)

PS: This would need to be projection aware areas. (e.g. currently drawing a circle does not draw a circle on the "ground" -- it does not take into account the distortion due to projection--)

@ghost ghost assigned brunosan Jan 26, 2014

@tmcw

This comment has been minimized.

Show comment
Hide comment
@tmcw

tmcw Jan 26, 2014

Contributor

See https://github.com/mapbox/leaflet-geodesy - would appreciate some tire-kicking of it

Contributor

tmcw commented Jan 26, 2014

See https://github.com/mapbox/leaflet-geodesy - would appreciate some tire-kicking of it

@gundersen

This comment has been minimized.

Show comment
Hide comment
@gundersen

gundersen Feb 4, 2014

Member

@tmcw nice to flag this. @brunosan if you get this working I could see this being a hot little micro-site that lets us talk to agg folks.

Member

gundersen commented Feb 4, 2014

@tmcw nice to flag this. @brunosan if you get this working I could see this being a hot little micro-site that lets us talk to agg folks.

@brunosan

This comment has been minimized.

Show comment
Hide comment
@brunosan

brunosan Feb 10, 2014

Thanks @tmcw .

Little time spent so far, but I´m going to jump to other things, so posting what I have:

function polygonArea(X, Y, numPoints) 
{ 
  area = 0;         // Accumulates area in the loop
  j = numPoints-1;  // The last vertex is the 'previous' one to the first

  for (i=0; i<numPoints; i++)
    { area = area +  (X[j]+X[i]) * (Y[j]-Y[i]); 
      j = i;  //j is previous vertex to i
    }
  return area/2;
}
map.on('draw:created', function (e) {
        var type = e.layerType,
            layer = e.layer;
            if (type === 'polygon') 
            {
                var area = L.GeometryUtil.geodesicArea(layer.getLatLngs())
                ...

But:

  • This seems a planar area (might be ok for now since our first usage is for high res agriculture).
  • Unsure if this covers circumferences. But in such case again restrict to planar, or learn here.
  • Not sure about the units. If pixels, then is just to multiply using the "z-> resolution" chart

Thanks @tmcw .

Little time spent so far, but I´m going to jump to other things, so posting what I have:

function polygonArea(X, Y, numPoints) 
{ 
  area = 0;         // Accumulates area in the loop
  j = numPoints-1;  // The last vertex is the 'previous' one to the first

  for (i=0; i<numPoints; i++)
    { area = area +  (X[j]+X[i]) * (Y[j]-Y[i]); 
      j = i;  //j is previous vertex to i
    }
  return area/2;
}
map.on('draw:created', function (e) {
        var type = e.layerType,
            layer = e.layer;
            if (type === 'polygon') 
            {
                var area = L.GeometryUtil.geodesicArea(layer.getLatLngs())
                ...

But:

  • This seems a planar area (might be ok for now since our first usage is for high res agriculture).
  • Unsure if this covers circumferences. But in such case again restrict to planar, or learn here.
  • Not sure about the units. If pixels, then is just to multiply using the "z-> resolution" chart
@tmcw

This comment has been minimized.

Show comment
Hide comment
@tmcw

tmcw Feb 10, 2014

Contributor

The lower-level area implementation is in https://github.com/mapbox/geojson-area/blob/master/index.js#L1 - it is geodesic & should correctly handle polygons with holes

Contributor

tmcw commented Feb 10, 2014

The lower-level area implementation is in https://github.com/mapbox/geojson-area/blob/master/index.js#L1 - it is geodesic & should correctly handle polygons with holes

@brunosan

This comment has been minimized.

Show comment
Hide comment

@brunosan brunosan closed this May 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment