GRASS GIS 8 Programmer's Manual 8.4.1(2025)-45ca3179ab
Loading...
Searching...
No Matches
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
18static struct state {
19 double M;
20} state;
21
22static 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 */
35void 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 */
47double 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
69double 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
double r
#define Radians(x)
Definition pi.h:6