00001
00017 #include <grass/gis.h>
00018
00019
00037 int G_window_overlap(const struct Cell_head *window,
00038 double N, double S, double E, double W)
00039 {
00040 if (window->north <= S)
00041 return 0;
00042 if (window->south >= N)
00043 return 0;
00044
00045 if (window->proj == PROJECTION_LL) {
00046 while (E < window->west) {
00047 E += 360.0;
00048 W += 360.0;
00049 }
00050 while (W > window->east) {
00051 E -= 360.0;
00052 W -= 360.0;
00053 }
00054 }
00055
00056 if (window->east <= W)
00057 return 0;
00058 if (window->west >= E)
00059 return 0;
00060
00061 return 1;
00062 }
00063
00064
00083 double G_window_percentage_overlap(const struct Cell_head *window,
00084 double N, double S, double E, double W)
00085 {
00086 double V, H;
00087 double n, s, e, w;
00088 double shift;
00089
00090
00091 if ((n = window->north) > N)
00092 n = N;
00093 if ((s = window->south) < S)
00094 s = S;
00095 V = n - s;
00096
00097 if (V <= 0.0)
00098 return 0.0;
00099
00100
00101 if (window->proj == PROJECTION_LL) {
00102 shift = 0.0;
00103 while (E + shift > window->east)
00104 shift -= 360.0;
00105 while (E + shift < window->west)
00106 shift += 360.0;
00107 E += shift;
00108 W += shift;
00109 }
00110
00111
00112 if ((e = window->east) > E)
00113 e = E;
00114 if ((w = window->west) < W)
00115 w = W;
00116 H = e - w;
00117 if (H <= 0.0)
00118 return 0.0;
00119
00120
00121 if (window->proj == PROJECTION_LL) {
00122 shift = 0.0;
00123 while (W + shift < window->west)
00124 shift += 360.0;
00125 while (W + shift > window->east)
00126 shift -= 360.0;
00127 if (shift) {
00128 E += shift;
00129 W += shift;
00130 if ((e = window->east) > E)
00131 e = E;
00132 if ((w = window->west) < W)
00133 w = W;
00134 H += e - w;
00135 }
00136 }
00137
00138 return (H * V) / ((N - S) * (E - W));
00139 }