GRASS 8 Programmer's Manual 8.6.0dev(2026)-c83afef6d3
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 * SPDX-FileCopyrightText: 2001-2009 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *
9 * \author Original author CERL
10 */
11
12#include <math.h>
13#include <grass/gis.h>
14#include "pi.h"
15
16static struct state {
17 double M;
18} state;
19
20static struct state *st = &state;
21
22/*!
23 * \brief Initialize calculations for sphere.
24 *
25 * Initializes raster area calculations for a sphere.
26 * The radius of the sphere is <i>r</i> and <i>s</i> is a scale factor to
27 * allow for calculations of a part of the zone (see
28 * G_begin_zone_area_on_ellipsoid()).
29 *
30 * \param r radius of sphere
31 * \param s scale factor
32 */
33void G_begin_zone_area_on_sphere(double r, double s)
34{
35 st->M = s * 2.0 * r * r * M_PI;
36}
37
38/*!
39 * \brief Calculates integral for area between two latitudes.
40 *
41 * \param lat latitude
42 *
43 * \return area value
44 */
45double G_darea0_on_sphere(double lat)
46{
47 return (st->M * sin(Radians(lat)));
48}
49
50/*!
51 * \brief Calculates area between latitudes.
52 *
53 * This routine shows how to calculate area between two lats, but
54 * isn't efficient for row by row since G_darea0_on_sphere() will
55 * be called twice for the same lat, once as a <i>south</i> then
56 * again as a <i>north</i>.
57 *
58 * Returns the area between latitudes <i>north</i> and <i>south</i>
59 * scaled by the factor <i>s</i> passed to
60 * G_begin_zone_area_on_sphere().
61 *
62 * \param north
63 * \param[in] south
64 * \return double
65 */
66double G_area_for_zone_on_sphere(double north, double south)
67{
68 return (G_darea0_on_sphere(north) - G_darea0_on_sphere(south));
69}
void G_begin_zone_area_on_sphere(double r, double s)
Initialize calculations for sphere.
Definition area_sphere.c:33
double G_darea0_on_sphere(double lat)
Calculates integral for area between two latitudes.
Definition area_sphere.c:45
double G_area_for_zone_on_sphere(double north, double south)
Calculates area between latitudes.
Definition area_sphere.c:66
#define M(row, col)
Definition georef.c:43
#define M_PI
Definition gis.h:154
#define Radians(x)
Definition pi.h:6
double r
Definition r_raster.c:37