GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
align_window.c
Go to the documentation of this file.
1 
17 #include <stdio.h>
18 #include <math.h>
19 #include <grass/gis.h>
20 
21 
41 char *G_align_window(struct Cell_head *window, const struct Cell_head *ref)
42 {
43  int preserve;
44 
45  window->ns_res = ref->ns_res;
46  window->ew_res = ref->ew_res;
47  window->zone = ref->zone;
48  window->proj = ref->proj;
49 
50  preserve = window->proj == PROJECTION_LL &&
51  window->east == (window->west + 360);
52  window->south =
53  G_row_to_northing(ceil(G_northing_to_row(window->south, ref)), ref);
54  window->north =
55  G_row_to_northing(floor(G_northing_to_row(window->north, ref)), ref);
56  window->east =
57  G_col_to_easting(ceil(G_easting_to_col(window->east, ref)), ref);
58  window->west =
59  G_col_to_easting(floor(G_easting_to_col(window->west, ref)), ref);
60 
61  if (window->proj == PROJECTION_LL) {
62  while (window->north > 90.0)
63  window->north -= window->ns_res;
64  while (window->south < -90.0)
65  window->south += window->ns_res;
66 
67  if (preserve)
68  window->east = window->west + 360;
69  else
70  while (window->east - window->west > 360.0)
71  window->east -= window->ew_res;
72  }
73 
74  return G_adjust_Cell_head(window, 0, 0);
75 }