Go to the documentation of this file.00001
00017 #include <stdio.h>
00018 #include <math.h>
00019 #include <grass/gis.h>
00020
00021
00041 char *G_align_window(struct Cell_head *window, const struct Cell_head *ref)
00042 {
00043 int preserve;
00044
00045 window->ns_res = ref->ns_res;
00046 window->ew_res = ref->ew_res;
00047 window->zone = ref->zone;
00048 window->proj = ref->proj;
00049
00050 preserve = window->proj == PROJECTION_LL &&
00051 window->east == (window->west + 360);
00052 window->south =
00053 G_row_to_northing(ceil(G_northing_to_row(window->south, ref)), ref);
00054 window->north =
00055 G_row_to_northing(floor(G_northing_to_row(window->north, ref)), ref);
00056 window->east =
00057 G_col_to_easting(ceil(G_easting_to_col(window->east, ref)), ref);
00058 window->west =
00059 G_col_to_easting(floor(G_easting_to_col(window->west, ref)), ref);
00060
00061 if (window->proj == PROJECTION_LL) {
00062 while (window->north > 90.0)
00063 window->north -= window->ns_res;
00064 while (window->south < -90.0)
00065 window->south += window->ns_res;
00066
00067 if (preserve)
00068 window->east = window->west + 360;
00069 else
00070 while (window->east - window->west > 360.0)
00071 window->east -= window->ew_res;
00072 }
00073
00074 return G_adjust_Cell_head(window, 0, 0);
00075 }