GRASS 8 Programmer's Manual 8.6.0dev(2026)-c83afef6d3
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 * SPDX-FileCopyrightText: 2001-2014 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *
9 * \author GRASS Development Team
10 *
11 * \date 1999-2014
12 */
13
14#include <grass/gis.h>
15
16/**
17 * \brief Adjusts window to a rectangular box.
18 *
19 * Creates a new window <b>dst</b> from a window <b>src</b> which fits
20 * into the rectangular box with dimensions <b>rows</b> by <b>cols</b>.
21 *
22 * \param[in] src source window
23 * \param[in,out] dst destination window
24 * \param[in] rows number of rows in box
25 * \param[in] cols number of columns in box
26 * \return
27 */
28void G_adjust_window_to_box(const struct Cell_head *src, struct Cell_head *dst,
29 int rows, int cols)
30{
31 double ew, ns;
32
33 *dst = *src;
34
35 /* calculate the effective resolutions */
36 ns = (src->ns_res * src->rows) / rows;
37 ew = (src->ew_res * src->cols) / cols;
38
39 /* set both resolutions equal to the larger */
40 if (ns > ew)
41 ew = ns;
42 else
43 ns = ew;
44
45 dst->ns_res = ns;
46 dst->ew_res = ew;
47
48 /* compute rows and cols */
49 dst->rows = (dst->north - dst->south) / dst->ns_res;
50 dst->cols = (dst->east - dst->west) / dst->ew_res;
51}
2D/3D raster map header (used also for region)
Definition gis.h:443
double ew_res
Resolution - east to west cell size for 2D data.
Definition gis.h:479
double north
Extent coordinates (north)
Definition gis.h:489
double east
Extent coordinates (east)
Definition gis.h:493
double ns_res
Resolution - north to south cell size for 2D data.
Definition gis.h:483
int rows
Number of rows for 2D data.
Definition gis.h:458
int cols
Number of columns for 2D data.
Definition gis.h:462
double south
Extent coordinates (south)
Definition gis.h:491
double west
Extent coordinates (west)
Definition gis.h:495
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:28