calculate polygon area
Yewondwossen Assefa
assefa at DMSOLUTIONS.CA
Wed Jul 19 11:15:01 PDT 2006
Steve,
I will add all the remaining geos support in PHP sometime next week.
Steve Lime wrote:
> Julien: The dev version of MapServer (which is quite stable) now has full support for GEOS operators in MapScript including a getArea() method. However, I don't know that Assefa has gotten around to adding them to PHP/MapScript. As far as I know the getArea method is planar...
>
> There is a distanceToPoint method for point objects I believe but again it is doing a simple planar distance computation.
>
> Steve
>
>
>>>>Julien Bessiere <julien.63 at FREE.FR> 07/18/06 8:12 AM >>>
>
> 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;
> }
> =====================================================================
>
--
----------------------------------------------------------------
Assefa Yewondwossen
Software Analyst
Email: assefa at dmsolutions.ca
http://www.dmsolutions.ca/
Phone: (613) 565-5056 (ext 14)
Fax: (613) 565-0925
----------------------------------------------------------------
More information about the MapServer-users
mailing list