|
@@ -16,19 +16,21 @@
|
|
|
|
|
|
#include <grass/gis.h>
|
|
|
|
|
|
+static struct state {
|
|
|
+ struct Cell_head window;
|
|
|
+ double square_meters;
|
|
|
+ int projection;
|
|
|
|
|
|
-static struct Cell_head window;
|
|
|
-static double square_meters;
|
|
|
-static int projection;
|
|
|
+ double units_to_meters_squared;
|
|
|
|
|
|
-static double units_to_meters_squared = 0.0;
|
|
|
-
|
|
|
-/* these next are for lat-long only */
|
|
|
-static int next_row;
|
|
|
-static double north_value;
|
|
|
-static double north;
|
|
|
-static double (*darea0) (double);
|
|
|
+ /* these next are for lat-long only */
|
|
|
+ int next_row;
|
|
|
+ double north_value;
|
|
|
+ double north;
|
|
|
+ double (*darea0) (double);
|
|
|
+} state;
|
|
|
|
|
|
+static struct state *st = &state;
|
|
|
|
|
|
/**
|
|
|
* \brief Begin cell area calculations.
|
|
@@ -52,26 +54,27 @@ int G_begin_cell_area_calculations(void)
|
|
|
double a, e2;
|
|
|
double factor;
|
|
|
|
|
|
- G_get_set_window(&window);
|
|
|
- switch (projection = window.proj) {
|
|
|
+ G_get_set_window(&st->window);
|
|
|
+ switch (st->projection = st->window.proj) {
|
|
|
case PROJECTION_LL:
|
|
|
G_get_ellipsoid_parameters(&a, &e2);
|
|
|
if (e2) {
|
|
|
- G_begin_zone_area_on_ellipsoid(a, e2, window.ew_res / 360.0);
|
|
|
- darea0 = G_darea0_on_ellipsoid;
|
|
|
+ G_begin_zone_area_on_ellipsoid(a, e2, st->window.ew_res / 360.0);
|
|
|
+ st->darea0 = G_darea0_on_ellipsoid;
|
|
|
}
|
|
|
else {
|
|
|
- G_begin_zone_area_on_sphere(a, window.ew_res / 360.0);
|
|
|
- darea0 = G_darea0_on_sphere;
|
|
|
+ G_begin_zone_area_on_sphere(a, st->window.ew_res / 360.0);
|
|
|
+ st->darea0 = G_darea0_on_sphere;
|
|
|
}
|
|
|
- next_row = 0;
|
|
|
- north_value = darea0(north = window.north);
|
|
|
+ st->next_row = 0;
|
|
|
+ st->north = st->window.north;
|
|
|
+ st->north_value = st->darea0(st->north);
|
|
|
return 2;
|
|
|
default:
|
|
|
- square_meters = window.ns_res * window.ew_res;
|
|
|
+ st->square_meters = st->window.ns_res * st->window.ew_res;
|
|
|
factor = G_database_units_to_meters_factor();
|
|
|
if (factor > 0.0)
|
|
|
- square_meters *= (factor * factor);
|
|
|
+ st->square_meters *= (factor * factor);
|
|
|
return (factor > 0.0);
|
|
|
}
|
|
|
}
|
|
@@ -93,17 +96,20 @@ double G_area_of_cell_at_row(int row)
|
|
|
double south_value;
|
|
|
double cell_area;
|
|
|
|
|
|
- if (projection != PROJECTION_LL)
|
|
|
- return square_meters;
|
|
|
+ if (st->projection != PROJECTION_LL)
|
|
|
+ return st->square_meters;
|
|
|
|
|
|
- if (row != next_row)
|
|
|
- north_value = darea0(north = window.north - row * window.ns_res);
|
|
|
+ if (row != st->next_row) {
|
|
|
+ st->north = st->window.north - row * st->window.ns_res;
|
|
|
+ st->north_value = st->darea0(st->north);
|
|
|
+ }
|
|
|
|
|
|
- south_value = darea0(north -= window.ns_res);
|
|
|
- cell_area = north_value - south_value;
|
|
|
+ st->north -= st->window.ns_res;
|
|
|
+ south_value = st->darea0(st->north);
|
|
|
+ cell_area = st->north_value - south_value;
|
|
|
|
|
|
- next_row = row + 1;
|
|
|
- north_value = south_value;
|
|
|
+ st->next_row = row + 1;
|
|
|
+ st->north_value = south_value;
|
|
|
|
|
|
return cell_area;
|
|
|
}
|
|
@@ -125,17 +131,17 @@ int G_begin_polygon_area_calculations(void)
|
|
|
double a, e2;
|
|
|
double factor;
|
|
|
|
|
|
- if ((projection = G_projection()) == PROJECTION_LL) {
|
|
|
+ if ((st->projection = G_projection()) == PROJECTION_LL) {
|
|
|
G_get_ellipsoid_parameters(&a, &e2);
|
|
|
G_begin_ellipsoid_polygon_area(a, e2);
|
|
|
return 2;
|
|
|
}
|
|
|
factor = G_database_units_to_meters_factor();
|
|
|
if (factor > 0.0) {
|
|
|
- units_to_meters_squared = factor * factor;
|
|
|
+ st->units_to_meters_squared = factor * factor;
|
|
|
return 1;
|
|
|
}
|
|
|
- units_to_meters_squared = 1.0;
|
|
|
+ st->units_to_meters_squared = 1.0;
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -166,10 +172,10 @@ double G_area_of_polygon(const double *x, const double *y, int n)
|
|
|
{
|
|
|
double area;
|
|
|
|
|
|
- if (projection == PROJECTION_LL)
|
|
|
+ if (st->projection == PROJECTION_LL)
|
|
|
area = G_ellipsoid_polygon_area(x, y, n);
|
|
|
else
|
|
|
- area = G_planimetric_polygon_area(x, y, n) * units_to_meters_squared;
|
|
|
+ area = G_planimetric_polygon_area(x, y, n) * st->units_to_meters_squared;
|
|
|
|
|
|
return area;
|
|
|
}
|