GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
area_sphere.c
Go to the documentation of this file.
1 /*!
2  * \file lib/gis/area_sphere.c
3  *
4  * \brief GIS Library - Sphereical 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 <math.h>
15 #include <grass/gis.h>
16 #include "pi.h"
17 
18 
19 static struct state {
20  double M;
21 } state;
22 
23 static struct state *st = &state;
24 
25 /*!
26  * \brief Initialize calculations for sphere.
27  *
28  * Initializes raster area calculations for a sphere.
29  * The radius of the sphere is <i>r</i> and <i>s</i> is a scale factor to
30  * allow for calculations of a part of the zone (see
31  * G_begin_zone_area_on_ellipsoid()).
32  *
33  * \param r radius of sphere
34  * \param s scale factor
35  */
36 void G_begin_zone_area_on_sphere(double r, double s)
37 {
38  st->M = s * 2.0 * r * r * M_PI;
39 }
40 
41 /*!
42  * \brief Calculates integral for area between two latitudes.
43  *
44  * \param lat latitude
45  *
46  * \return area value
47  */
48 double G_darea0_on_sphere(double lat)
49 {
50  return (st->M * sin(Radians(lat)));
51 }
52 
53 /*!
54  * \brief Calculates area between latitudes.
55  *
56  * This routine shows how to calculate area between two lats, but
57  * isn't efficient for row by row since G_darea0_on_sphere() will
58  * be called twice for the same lat, once as a <i>south</i> then
59  * again as a <i>north</i>.
60  *
61  * Returns the area between latitudes <i>north</i> and <i>south</i>
62  * scaled by the factor <i>s</i> passed to
63  * G_begin_zone_area_on_sphere().
64  *
65  * \param north
66  * \param[in] south
67  * \return double
68  */
69 
70 double G_area_for_zone_on_sphere(double north, double south)
71 {
72  return (G_darea0_on_sphere(north) - G_darea0_on_sphere(south));
73 }
double G_darea0_on_sphere(double lat)
Calculates integral for area between two latitudes.
Definition: area_sphere.c:48
#define M_PI
Definition: gis.h:134
struct state * st
Definition: parser.c:104
void G_begin_zone_area_on_sphere(double r, double s)
Initialize calculations for sphere.
Definition: area_sphere.c:36
#define Radians(x)
Definition: pi.h:6
#define M(row, col)
Definition: georef.c:49
double G_area_for_zone_on_sphere(double north, double south)
Calculates area between latitudes.
Definition: area_sphere.c:70
struct state state
Definition: parser.c:103
double r
Definition: r_raster.c:39