calculate polygon area

Umberto Nicoletti umberto.nicoletti at GMAIL.COM
Tue Jul 18 06:23:45 PDT 2006


If you have GEOS support you can try to use the geos msGEOSArea() function.

HTH,
Umberto

On 7/18/06, Julien Bessiere <julien.63 at free.fr> wrote:
> Hi,
> I'm using phpMapscript / Mapserver.
> I wrote a little script that allows users to draw polygons on the map. I try to
> figure out how to calculate the area of this polygon, but so far...
> I found a formula and wrote the script below but as i'm using decimal latitude
> and longitude, the result is unusable :
> So my questions is :
>
> 1- Does phpmapscript has a function to calculate area
> (something like distanceToPoint(pointObj poPoint))?
> 2- If no, how to calculate area wiht lat long coordinates?
>
> thanks for your advices,
>
> Julien
>
> ============================================================
> function polygonArea($polygon_coordinates){
>         $array_length = count($polygon_coordinates);
>         if ($array_length > 2){
>                 // add the first coordinates at the end to close de polygon
>
> array_push($polygon_coordinates,array($polygon_coordinates[0][0],$polygon_coordinates[0][1]));
>                 $polygon_area = 0;
>                 for ($i=0;$i <= $array_length;$i++){
>                         $polygon_area += (
>                                 ($polygon_coordinates[$i][0] *
> $polygon_coordinates[$i+1][1])-
>                                 ($polygon_coordinates[$i][1] *
> $polygon_coordinates[$i+1][0]));
>                 }
>                 $polygon_area = abs($polygon_area / 2);
>         }
>         else {
>                 $polygon_area = 'need at least 3 points';
>         }
>         return $polygon_area;
> }
> =====================================================================
>



More information about the MapServer-users mailing list