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