GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 }
double G_darea0_on_sphere(double lat)
Calculates integral for area between two latitudes.
Definition: area_sphere.c:55
int G_begin_zone_area_on_sphere(double r, double s)
Initialize calculations for sphere.
Definition: area_sphere.c:42
double G_area_of_polygon(const double *x, const double *y, int n)
Area in square meters of polygon.
Definition: gis/area.c:165
int G_get_set_window(struct Cell_head *window)
Get the current working window.
Definition: set_window.c:30
double G_area_of_cell_at_row(int row)
Cell area in specified row.
Definition: gis/area.c:91
int G_get_ellipsoid_parameters(double *a, double *e2)
get ellipsoid parameters
Definition: get_ellipse.c:66
double G_planimetric_polygon_area(const double *x, const double *y, int n)
Calculates planimetric polygon area.
Definition: area_poly2.c:29
int y
Definition: plot.c:34
double G_darea0_on_ellipsoid(double lat)
Calculate integral for area between two latitudes.
Definition: area_ellipse.c:69
int G_begin_zone_area_on_ellipsoid(double a, double e2, double s)
Begin area calculations for ellipsoid.
Definition: area_ellipse.c:50
int G_begin_polygon_area_calculations(void)
Begin polygon area calculations.
Definition: gis/area.c:123
tuple window
Definition: tools.py:543
int G_begin_cell_area_calculations(void)
Begin cell area calculations.
Definition: gis/area.c:50
int G_begin_ellipsoid_polygon_area(double a, double e2)
Begin area calculations.
Definition: area_poly1.c:65
double G_ellipsoid_polygon_area(const double *lon, const double *lat, int n)
Area of lat-long polygon.
Definition: area_poly1.c:137
double G_database_units_to_meters_factor(void)
conversion to meters
Definition: proj3.c:80
int n
Definition: dataquad.c:291
int G_projection(void)
query cartographic projection
Definition: proj1.c:33