You are here: > ESRI Forums > arcgis server forums > Thread Replies

ArcGIS Server Forums

ArcGIS API for Flex forum

Calculate area using x,y coordinates   Douglas Guess May 04, 2009
Re: Calculate area using x,y coordinates   Todd Giberson May 05, 2009
Re: Calculate area using x,y coordinates   Douglas Guess May 07, 2009
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Calculate area using x,y coordinates 
Author Douglas Guess 
Date May 04, 2009 
Message Our data is in a custom projection so I canít use a WKID in the Geometry Service for calculations. Iím trying to calculate the area of a drawn polygon by using itís x,y coordinates by modifying the existing sample DrawWidget.mxml. How can I calculate the area of an Irregular polygon by using the x,y coordinates? Does anyone have some sample code on how to do this sort of thing???

Thanks.
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Calculate area using x,y coordinates 
Author Todd Giberson 
Date May 05, 2009 
Message If you are just trying to calculate the area of a polygon from a list of x,y coordinates, the general method is to loop through the coordinates performing a cross-product calculation between consecutive coordinate pairs, while summing up a running total. The running total is then divided by 2 and the absolute value is taken to yield the final result or area of the polygon.

Care must be taken to close the polygon by traversing the coordinates back to the origin point. For example, if I have a 5-sided polygon defined by the array

0,1
3,3
5,3
6,2
5,0

the last calculation would involve the 5,0 point and the 0,1 origin point.

If n is the number of coordinates in the polygon, and assuming a zero-based array, where the first coordinates are at array index 0 and the last coordinates are at index n-1, computer code would look something like the following, depending on the language used and your array: 
 
running_total = 0;
for (i=0; i<n-1; i++)
{
  running_total += x[i]*y[i+1] - x[i+1]*y[i];
}
running_total += x[n-1]*y[0] - x[0]*y[n-1];   // traverse back to the origin point
area = abs(running_total / 2.0);
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Calculate area using x,y coordinates 
Author Douglas Guess 
Date May 07, 2009 
Message Thanks Todd, I'll give it a shot.