Recommend this page to a friend! 
All requests  >  Area of a polygon  >  Request new recommendation  >  Featured requests  >  No recommendations 
by fikar  8 years ago (20150903)
+3  I have tried the calculate distance class, but that is not good for this. Now how about calculate polygon area in a map? 
2. by Anthony Amolochitis  8 years ago (20150904) Reply
Do you need an exact area or an approximate area?
Approximate area can use summations of length and height of leftmost to rightmost points from bottom up, top down, etc... The smaller the rectangular height, the closer to accurate you will be. That isn't the most efficient, but it is a start.
If you need the exact area, you will need to use integration of a function. If you can define a function to draw the polygon, then it can be integrated. Maybe by breaking the polygon down to multiple triangles will help with this.
Sounds like it's own little system. I will dwell on it some more. Great problem!
1. by Manuel Lemos  8 years ago (20150904) Reply
That is a tough problem to do in pure PHP if you do not know integral calculus. I do not know enough about it to figure an algorithm.
Anyway, I think Google Maps API has function to calculate areas defined by polygons given their latitude and longitude coordinates.
3. by Olivier Plathey  8 years ago (20150905) in reply to comment 1 by Manuel Lemos Comment
There's no need to do any integral calculus.
www.mathwords.com/a/area_convex_polygon.htm
4. by Samuel Adeshina  8 years ago (20150905) in reply to comment 3 by Olivier Plathey Comment
Olivier Plathey, there's something called efficiency. Most of the Formulas on that page are meant for calculating the area of an irregular polygon by hand, they've not been properly optimized as an efficient algorithm should. These formulas would fail in situation where you need to calculate the area of a city from coordinates gotten from google maps or something similar
5. by Olivier Plathey  8 years ago (20150905) in reply to comment 4 by Samuel Adeshina Comment
Are you serious? Of course the formula is efficient. There are only some additions and multiplications. You can't do better.
You will find a JS implementation here:
www.mathopenref.com/coordpolygonarea2.html
The function has only 6 lines!
6. by Manuel Lemos  8 years ago (20150905) in reply to comment 3 by Olivier Plathey Comment
Well the Earth is round, not flat. Those calculations seem to be meant to calculate areas of polygons defined on flat surfaces. That is why I suppose it may require integral calculus for polygons defined on round surfaces to be really accurate.
Now, so polygons defined by vertices that are very close, the surface is almost flat. In that case those calculations for flat polygons would do.
7. by Samuel Adeshina  8 years ago (20150906) in reply to comment 6 by Manuel Lemos Comment
Yeah, the best method for calculating the area of an hollow irregular polygonal shape or object is to integrate. Using Green's integral Theorem (Search for Green's Theorem on Wikipedia, external links are not allowed here), a formular can be derived for determining the area of an irregular polygon
+2  by Samuel Adeshina 895  8 years ago (20150905) Comment Check Out This Package. It accepts the coordinates of the vertices of the polygon you want to calculate and uses green's theorem to determine its area. It can also be used to determine the perimeter (distance) of a polygonal shape using the well known distance formula in physics. 
1. by Manuel Lemos  8 years ago (20150907) Reply
Yes, this can be used as an approximate solution for map areas defined by vertices not very far from each other, as when they are close you can consider the Earth is practically flat.
Anyway for mapping calculations there still needs to be some kind of conversion between latitude and longitude and miles or kilometers, at least to a reference point.
2. by Samuel Adeshina Reply
 8 years ago (20150908) in reply to comment 1 by Manuel LemosYes, thanks Mr. Manuel
I just opened a new issue for that on the package's github repo. Will improve the algorithm as soon as possible
Recommend package  
