Polygon area calculation using Latitude and Longitude generated from Cartesian space and a world file

后端 未结 7 1962
孤街浪徒
孤街浪徒 2020-11-27 22:16

Given a series of GPS coordinate pairs, I need to calculate the area of a polygon (n-gon). This is relatively small (not larger than 50,000 sqft). The geocodes are created

7条回答
  •  萌比男神i
    2020-11-27 22:29

    Adapted RiskyPathak's snippet to PHP

    function CalculatePolygonArea($coordinates) {
        $area = 0;
        $coordinatesCount = sizeof($coordinates);
        if ($coordinatesCount > 2) {
          for ($i = 0; $i < $coordinatesCount - 1; $i++) {
            $p1 = $coordinates[$i];
            $p2 = $coordinates[$i + 1];
            $p1Longitude = $p1[0];
            $p2Longitude = $p2[0];
            $p1Latitude = $p1[1];
            $p2Latitude = $p2[1];
            $area += ConvertToRadian($p2Longitude - $p1Longitude) * (2 + sin(ConvertToRadian($p1Latitude)) + sin(ConvertToRadian($p2Latitude)));
          }
        $area = $area * 6378137 * 6378137 / 2;
        }
        return abs(round(($area));
    }
    
    function ConvertToRadian($input) {
        $output = $input * pi() / 180;
        return $output;
    }
    

提交回复
热议问题