GRASS GIS 8 Programmer's Manual
8.5.0dev(2024)-36359e2344
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
}
G_planimetric_polygon_area
double G_planimetric_polygon_area(const double *x, const double *y, int n)
Calculates planimetric polygon area.
Definition:
area_poly2.c:25
gis.h
x
#define x
lib
gis
area_poly2.c
Generated on Thu Nov 21 2024 07:03:24 for GRASS GIS 8 Programmer's Manual by
1.9.1