GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
gis/area.c
Go to the documentation of this file.
1 
17 #include <grass/gis.h>
18 
19 
20 static struct Cell_head window;
21 static double square_meters;
22 static int projection;
23 
24 static double units_to_meters_squared = 0.0;
25 
26 /* these next are for lat-long only */
27 static int next_row;
28 static double north_value;
29 static double north;
30 static double (*darea0) (double);
31 
32 
51 {
52  double a, e2;
53  double factor;
54 
56  switch (projection = window.proj) {
57  case PROJECTION_LL:
59  if (e2) {
60  G_begin_zone_area_on_ellipsoid(a, e2, window.ew_res / 360.0);
61  darea0 = G_darea0_on_ellipsoid;
62  }
63  else {
64  G_begin_zone_area_on_sphere(a, window.ew_res / 360.0);
65  darea0 = G_darea0_on_sphere;
66  }
67  next_row = 0;
68  north_value = darea0(north = window.north);
69  return 2;
70  default:
71  square_meters = window.ns_res * window.ew_res;
73  if (factor > 0.0)
74  square_meters *= (factor * factor);
75  return (factor > 0.0);
76  }
77 }
78 
79 
91 double G_area_of_cell_at_row(int row)
92 {
93  register double south_value;
94  register double cell_area;
95 
96  if (projection != PROJECTION_LL)
97  return square_meters;
98 
99  if (row != next_row)
100  north_value = darea0(north = window.north - row * window.ns_res);
101 
102  south_value = darea0(north -= window.ns_res);
103  cell_area = north_value - south_value;
104 
105  next_row = row + 1;
106  north_value = south_value;
107 
108  return cell_area;
109 }
110 
111 
124 {
125  double a, e2;
126  double factor;
127 
128  if ((projection = G_projection()) == PROJECTION_LL) {
131  return 2;
132  }
134  if (factor > 0.0) {
135  units_to_meters_squared = factor * factor;
136  return 1;
137  }
138  units_to_meters_squared = 1.0;
139  return 0;
140 }
141 
142 
165 double G_area_of_polygon(const double *x, const double *y, int n)
166 {
167  double area;
168 
169  if (projection == PROJECTION_LL)
170  area = G_ellipsoid_polygon_area(x, y, n);
171  else
172  area = G_planimetric_polygon_area(x, y, n) * units_to_meters_squared;
173 
174  return area;
175 }