GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
area_poly2.c
Go to the documentation of this file.
1 /*!
2  * \file lib/gis/area_poly2.c
3  *
4  * \brief GIS Library - Planimetric polygon area calculation routines.
5  *
6  * (C) 2001-2009 by the GRASS Development Team
7  *
8  * This program is free software under the GNU General Public License
9  * (>=v2). Read the file COPYING that comes with GRASS for details.
10  *
11  * \author Original author CERL
12  */
13 
14 #include <grass/gis.h>
15 
16 /*!
17  * \brief Calculates planimetric polygon area.
18  *
19  * \param x array of x values
20  * \param y array of y values
21  * \param n number of x,y pairs
22 
23  * \return polygon area in map units
24  */
25 double G_planimetric_polygon_area(const double *x, const double *y, int n)
26 {
27  double x1, y1, x2, y2;
28  double area;
29 
30  x2 = x[n - 1];
31  y2 = y[n - 1];
32 
33  area = 0;
34  while (--n >= 0) {
35  x1 = x2;
36  y1 = y2;
37 
38  x2 = *x++;
39  y2 = *y++;
40 
41  area += (y2 + y1) * (x2 - x1);
42  }
43 
44  if ((area /= 2.0) < 0.0)
45  area = -area;
46 
47  return area;
48 }
double G_planimetric_polygon_area(const double *x, const double *y, int n)
Calculates planimetric polygon area.
Definition: area_poly2.c:25
#define x