GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 }
double G_easting_to_col(double east, const struct Cell_head *window)
Easting to column.
Definition: window_map.c:198
double G_row_to_northing(double row, const struct Cell_head *window)
Row to northing.
Definition: window_map.c:223
double G_col_to_easting(double col, const struct Cell_head *window)
Column to easting.
Definition: window_map.c:243
tuple window
Definition: tools.py:543
char * G_adjust_Cell_head(struct Cell_head *cellhd, int row_flag, int col_flag)
Adjust cell header.
Definition: adj_cellhd.c:43
double G_northing_to_row(double north, const struct Cell_head *window)
Northing to row.
Definition: window_map.c:129
char * G_align_window(struct Cell_head *window, const struct Cell_head *ref)
Align two regions.
Definition: align_window.c:41