I am using GeoPHP to get the area of my GeoJson polygons.
Here is my function below.
/**
* gets the areas in acres for field geojson polygons
* @return string
*/
public function polygon_area($json)
{
// get the geoPHP library
require_once(__DIR__ . '/vendor/GeoPHP/geoPHP.inc');
// create the json array as string
$geoJson = '{"type":"Polygon","coordinates":['.$json.']}';
// create the polygon geoPHP object
$polygon = geoPHP::load($geoJson,'json');
// the area of the polygon
$area = $polygon->getArea();
// convert area into acres
$acre = $area * 247.105;
// return the geophp area
return $area;
}
This is assuming that the areas returned from the polygon json, is square kilometres. But I don't think it is.
See below the values returned using the GeoPHP $polygon->getArea() function from the above code.
Area: 1.21816181142E-5
Area: 4.06926334051E-6
Area: 5.59853614135E-6
Area: 3.74998247921E-6
Area: 5.91964048269E-6
Area: 2.50475049057E-6
Area: 5.84341879772E-7
Area: 7.7207101441E-6
Area: 4.27298301986E-6
Area: 2.99669066806E-6
Area: 1.76724087666E-5
What I can't understand, is what unit of measurement are these areas calculated in using GeoPHP. There documentation does any unit at all?
When I convert to acres, and round($acre, 2) the values come out at zero. These polygon areas should be ranging from 5-15 acres.
Does anyone know how convert the areas to acres or km2?
Thanks in advance.