align_window.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <math.h>
00003 #include <grass/gis.h>
00004 
00025 char *
00026 G_align_window  (struct Cell_head *window, struct Cell_head *ref)
00027 
00028 {
00029     int preserve;
00030 
00031     window->ns_res = ref->ns_res;
00032     window->ew_res = ref->ew_res;
00033     window->zone   = ref->zone;
00034     window->proj   = ref->proj;
00035 
00036     preserve = window->proj == PROJECTION_LL && window->east == (window->west+360);
00037     window->south =
00038         G_row_to_northing (ceil(G_northing_to_row (window->south, ref)), ref);
00039     window->north =
00040         G_row_to_northing (floor(G_northing_to_row (window->north, ref)), ref);
00041     window->east =
00042         G_col_to_easting (ceil(G_easting_to_col (window->east, ref)), ref);
00043     window->west =
00044         G_col_to_easting (floor(G_easting_to_col (window->west, ref)), ref);
00045 
00046     if (window->proj == PROJECTION_LL)
00047     {
00048         while (window->north > 90.0)
00049             window->north -= window->ns_res;
00050         while (window->south < -90.0)
00051             window->south += window->ns_res;
00052         if (preserve)
00053             window->east = window->west + 360;
00054         else
00055             while (window->east - window->west > 360.0)
00056                 window->east -= window->ew_res;
00057     }
00058 
00059     return G_adjust_Cell_head (window, 0, 0);
00060 }

Generated on Fri Nov 21 11:02:17 2008 for GRASS by  doxygen 1.5.1