GRASS 8 Programmer's Manual 8.6.0dev(2026)-1878fdfec5
Loading...
Searching...
No Matches
area_ellipse.c
Go to the documentation of this file.
1/*!
2 * \file lib/gis/area_ellipse.c
3 *
4 * \brief GIS Library - Ellipse area 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 E;
18 double M;
19} state;
20
21static struct state *st = &state;
22
23/*
24 * a is semi-major axis, e2 is eccentricity squared, s is a scale factor
25 * code will fail if e2==0 (sphere)
26 */
27
28/*!
29 * \brief Begin area calculations for ellipsoid.
30 *
31 * Initializes raster area calculations for an ellipsoid, where <i>a</i>
32 * is the semi-major axis of the ellipse (in meters), <i>e2</i> is the
33 * ellipsoid eccentricity squared, and <i>s</i> is a scale factor to
34 * allow for calculations of part of the zone (<i>s</i>=1.0 is full
35 * zone, <i>s</i>=0.5 is half the zone, and <i>s</i>=360/ew_res is for a
36 * single grid cell).
37 *
38 * <b>Note:</b> <i>e2</i> must be positive. A negative value makes no
39 * sense, and zero implies a sphere.
40 *
41 * \param a semi-major axis
42 * \param e2 ellipsoid eccentricity
43 * \param s scale factor
44 */
45void G_begin_zone_area_on_ellipsoid(double a, double e2, double s)
46{
47 st->E = sqrt(e2);
48 st->M = s * a * a * M_PI * (1 - e2) / st->E;
49}
50
51/*!
52 * \brief Calculate integral for area between two latitudes.
53 *
54 * This routine is part of the integral for the area between two
55 * latitudes.
56 *
57 * \param lat latitude
58 *
59 * \return cell area
60 */
62{
63 double x;
64
65 x = st->E * sin(Radians(lat));
66
67 return (st->M * (x / (1.0 - x * x) + 0.5 * log((1.0 + x) / (1.0 - x))));
68}
69
70/*!
71 * \brief Calculates area between latitudes.
72 *
73 * This routine shows how to calculate area between two lats, but
74 * isn't efficient for row by row since G_darea0_on_ellipsoid()
75 * will be called twice for the same lat, once as a <i>south</i> then
76 * again as a <i>north</i>.
77 *
78 * Returns the area between latitudes <i>north</i> and <i>south</i>
79 * scaled by the factor <i>s</i> passed to
80 * G_begin_zone_area_on_ellipsoid().
81 *
82 * \param north north coordinate
83 * \param south south coordinate
84 *
85 * \return cell area
86 */
87double G_area_for_zone_on_ellipsoid(double north, double south)
88{
89 return (G_darea0_on_ellipsoid(north) - G_darea0_on_ellipsoid(south));
90}
double G_darea0_on_ellipsoid(double lat)
Calculate integral for area between two latitudes.
double G_area_for_zone_on_ellipsoid(double north, double south)
Calculates area between latitudes.
void G_begin_zone_area_on_ellipsoid(double a, double e2, double s)
Begin area calculations for ellipsoid.
#define M(row, col)
Definition georef.c:43
#define M_PI
Definition gis.h:154
#define Radians(x)
Definition pi.h:6
#define x