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