00001 #include <grass/gis.h>
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 int G_window_overlap ( struct Cell_head *window,
00012 double N,double S,double E,double W)
00013 {
00014 if (window->north <= S) return 0;
00015 if (window->south >= N) return 0;
00016
00017 if (window->proj == PROJECTION_LL)
00018 {
00019 while (E < window->west)
00020 {
00021 E += 360.0;
00022 W += 360.0;
00023 }
00024 while (W > window->east)
00025 {
00026 E -= 360.0;
00027 W -= 360.0;
00028 }
00029 }
00030
00031 if (window->east <= W) return 0;
00032 if (window->west >= E) return 0;
00033
00034 return 1;
00035 }
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 double G_window_percentage_overlap ( struct Cell_head *window,
00048 double N,double S,double E,double W)
00049 {
00050 double V,H;
00051 double n,s,e,w;
00052 double shift;
00053
00054
00055 if ((n = window->north) > N) n = N;
00056 if ((s = window->south) < S) s = S;
00057 V = n - s;
00058 if(V <= 0.0) return 0.0 ;
00059
00060
00061 if (window->proj == PROJECTION_LL)
00062 {
00063 shift = 0.0;
00064 while (E+shift > window->east)
00065 shift -= 360.0;
00066 while (E+shift < window->west)
00067 shift += 360.0;
00068 E += shift;
00069 W += shift;
00070 }
00071
00072
00073 if ((e = window->east) > E) e = E;
00074 if ((w = window->west) < W) w = W;
00075 H = e - w;
00076 if(H <= 0.0) return 0.0 ;
00077
00078
00079 if (window->proj == PROJECTION_LL)
00080 {
00081 shift = 0.0;
00082 while (W+shift < window->west)
00083 shift += 360.0;
00084 while (W+shift > window->east)
00085 shift -= 360.0;
00086 if (shift)
00087 {
00088 E += shift;
00089 W += shift;
00090 if ((e = window->east) > E) e = E;
00091 if ((w = window->west) < W) w = W;
00092 H += e - w;
00093 }
00094 }
00095
00096 return (H*V)/((N-S)*(E-W));
00097 }