GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
wind_overlap.c
Go to the documentation of this file.
1 
17 #include <grass/gis.h>
18 
19 
37 int G_window_overlap(const struct Cell_head *window,
38  double N, double S, double E, double W)
39 {
40  if (window->north <= S)
41  return 0;
42  if (window->south >= N)
43  return 0;
44 
45  if (window->proj == PROJECTION_LL) {
46  while (E < window->west) {
47  E += 360.0;
48  W += 360.0;
49  }
50  while (W > window->east) {
51  E -= 360.0;
52  W -= 360.0;
53  }
54  }
55 
56  if (window->east <= W)
57  return 0;
58  if (window->west >= E)
59  return 0;
60 
61  return 1;
62 }
63 
64 
83 double G_window_percentage_overlap(const struct Cell_head *window,
84  double N, double S, double E, double W)
85 {
86  double V, H;
87  double n, s, e, w;
88  double shift;
89 
90  /* vertical height of the box that overlaps the window */
91  if ((n = window->north) > N)
92  n = N;
93  if ((s = window->south) < S)
94  s = S;
95  V = n - s;
96 
97  if (V <= 0.0)
98  return 0.0;
99 
100  /* global wrap-around, part 1 */
101  if (window->proj == PROJECTION_LL) {
102  shift = 0.0;
103  while (E + shift > window->east)
104  shift -= 360.0;
105  while (E + shift < window->west)
106  shift += 360.0;
107  E += shift;
108  W += shift;
109  }
110 
111  /* horizontal width of the box that overlaps the window */
112  if ((e = window->east) > E)
113  e = E;
114  if ((w = window->west) < W)
115  w = W;
116  H = e - w;
117  if (H <= 0.0)
118  return 0.0;
119 
120  /* global wrap-around, part 2 */
121  if (window->proj == PROJECTION_LL) {
122  shift = 0.0;
123  while (W + shift < window->west)
124  shift += 360.0;
125  while (W + shift > window->east)
126  shift -= 360.0;
127  if (shift) {
128  E += shift;
129  W += shift;
130  if ((e = window->east) > E)
131  e = E;
132  if ((w = window->west) < W)
133  w = W;
134  H += e - w;
135  }
136  }
137 
138  return (H * V) / ((N - S) * (E - W));
139 }
double G_window_percentage_overlap(const struct Cell_head *window, double N, double S, double E, double W)
Determines percentage of box is contained in the window.
Definition: wind_overlap.c:83
tuple window
Definition: tools.py:543
#define H
Definition: as177.c:15
#define N
Definition: inverse.c:8
int G_window_overlap(const struct Cell_head *window, double N, double S, double E, double W)
Determins if a box overlays a map window.
Definition: wind_overlap.c:37
int n
Definition: dataquad.c:291