GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
wind_2_box.c
Go to the documentation of this file.
1 
2 /*!
3  * \file lib/gis/wind_2_box.c
4  *
5  * \brief GIS Library - Window box functions.
6  *
7  * (C) 2001-2014 by the GRASS Development Team
8  *
9  * This program is free software under the GNU General Public License
10  * (>=v2). Read the file COPYING that comes with GRASS for details.
11  *
12  * \author GRASS GIS Development Team
13  *
14  * \date 1999-2014
15  */
16 
17 #include <grass/gis.h>
18 
19 
20 /**
21  * \brief Adjusts window to a rectangular box.
22  *
23  * Creates a new window <b>dst</b> from a window <b>src</b> which fits
24  * into the rectangular box with dimensions <b>rows</b> by <b>cols</b>.
25  *
26  * \param[in] src source window
27  * \param[in,out] dst destination window
28  * \param[in] rows number of rows in box
29  * \param[in] cols number of columns in box
30  * \return
31  */
32 
33 void G_adjust_window_to_box(const struct Cell_head *src,
34  struct Cell_head *dst, int rows, int cols)
35 {
36  double ew, ns;
37 
38  *dst = *src;
39 
40  /* calculate the effective resolutions */
41  ns = (src->ns_res * src->rows) / rows;
42  ew = (src->ew_res * src->cols) / cols;
43 
44  /* set both resolutions equal to the larger */
45  if (ns > ew)
46  ew = ns;
47  else
48  ns = ew;
49 
50  dst->ns_res = ns;
51  dst->ew_res = ew;
52 
53  /* compute rows and cols */
54  dst->rows = (dst->north - dst->south) / dst->ns_res;
55  dst->cols = (dst->east - dst->west) / dst->ew_res;
56 }
2D/3D raster map header (used also for region)
Definition: gis.h:423
double west
Extent coordinates (west)
Definition: gis.h:475
char * dst
Definition: lz4.h:599
double north
Extent coordinates (north)
Definition: gis.h:469
double south
Extent coordinates (south)
Definition: gis.h:471
int cols
Number of columns for 2D data.
Definition: gis.h:442
double ns_res
Resolution - north to south cell size for 2D data.
Definition: gis.h:463
double east
Extent coordinates (east)
Definition: gis.h:473
void G_adjust_window_to_box(const struct Cell_head *src, struct Cell_head *dst, int rows, int cols)
Adjusts window to a rectangular box.
Definition: wind_2_box.c:33
double ew_res
Resolution - east to west cell size for 2D data.
Definition: gis.h:459
int rows
Number of rows for 2D data.
Definition: gis.h:438