GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
window_map.c File Reference

GIS Library - Window mapping functions. More...

#include <stdlib.h>
#include <grass/gis.h>
#include "G.h"
Include dependency graph for window_map.c:

Go to the source code of this file.

Macros

#define alloc_index(n)   (COLUMN_MAPPING *) G_malloc((n)*sizeof(COLUMN_MAPPING))
 

Functions

int G__create_window_mapping (int fd)
 Create window mapping. More...
 
double G_northing_to_row (double north, const struct Cell_head *window)
 Northing to row. More...
 
double G_adjust_east_longitude (double east, double west)
 Adjust east longitude. More...
 
double G_adjust_easting (double east, const struct Cell_head *window)
 Returns east larger than west. More...
 
double G_easting_to_col (double east, const struct Cell_head *window)
 Easting to column. More...
 
double G_row_to_northing (double row, const struct Cell_head *window)
 Row to northing. More...
 
double G_col_to_easting (double col, const struct Cell_head *window)
 Column to easting. More...
 
int G_window_rows (void)
 Number of rows in active window. More...
 
int G_window_cols (void)
 Number of columns in active window. More...
 
int G__init_window (void)
 Initialize window. More...
 
int G_row_repeat_nomask (int fd, int row)
 Loops rows until mismatch?. More...
 

Detailed Description

GIS Library - Window mapping functions.

(C) 2001-2008 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
GRASS GIS Development Team
Date
1999-2008

Definition in file window_map.c.

Macro Definition Documentation

#define alloc_index (   n)    (COLUMN_MAPPING *) G_malloc((n)*sizeof(COLUMN_MAPPING))

Definition at line 22 of file window_map.c.

Referenced by G__create_window_mapping().

Function Documentation

int G__create_window_mapping ( int  fd)

Create window mapping.

Creates mapping from cell header into window. The boundaries and resolution of the two spaces do not have to be the same or aligned in any way.

Parameters
[in]fdfile descriptor
Returns
always returns 0

Definition at line 36 of file window_map.c.

References alloc_index, fileinfo::C1, fileinfo::C2, fileinfo::cellhd, fileinfo::col_map, fd, G__::fileinfo, G__init_window(), G_debug(), G_free(), fileinfo::open_mode, OPEN_OLD, and G__::window.

Referenced by G__open_cell_old(), and G_set_window().

int G__init_window ( void  )

Initialize window.

Returns
always returns 0

Definition at line 320 of file window_map.c.

References G_get_window(), G__::window, and G__::window_set.

Referenced by G__create_window_mapping(), G__open_cell_old(), G_get_set_window(), G_window_cols(), and G_window_rows().

double G_adjust_east_longitude ( double  east,
double  west 
)

Adjust east longitude.

This routine returns an equivalent east that is larger, but no more than 360 larger than the west coordinate.
Note: This routine should be used only with latitude-longitude coordinates.

Parameters
[in,out]east
[in]west
Returns
east coordinate

Definition at line 149 of file window_map.c.

Referenced by G_adjust_easting().

double G_adjust_easting ( double  east,
const struct Cell_head *  window 
)

Returns east larger than west.

If the region projection is PROJECTION_LL, then this routine returns an equivalent east that is larger, but no more than 360 degrees larger, than the coordinate for the western edge of the region. Otherwise no adjustment is made and the original east is returned.

Parameters
[in,out]east
[in]window
Returns
east coordinate

Definition at line 174 of file window_map.c.

References G_adjust_east_longitude().

Referenced by G_easting_to_col(), G_plot_where_en(), G_plot_where_xy(), and G_site_in_region().

double G_col_to_easting ( double  col,
const struct Cell_head *  window 
)

Column to easting.

Converts a col relative to a window to an easting.
Note: col is a double:

  • col+0.0 will return the easting for the western edge of the column.
  • col+0.5 will return the easting for the center of the column.
  • col+1.0 will return the easting for the eastern edge of the column.
Parameters
[in]col
[in]window
Returns
east coordinate

Definition at line 243 of file window_map.c.

Referenced by G_align_window().

double G_easting_to_col ( double  east,
const struct Cell_head *  window 
)

Easting to column.

Converts east relative to a window to a column.
Note: The result is a double. Casting it to an int will give the column number.

Parameters
[in]east
[in]window
Returns
column id

Definition at line 198 of file window_map.c.

References G_adjust_easting().

Referenced by G_align_window(), G_get_raster_sample_bilinear(), G_get_raster_sample_cubic(), and G_get_raster_sample_nearest().

double G_northing_to_row ( double  north,
const struct Cell_head *  window 
)

Northing to row.

Converts a northing relative to a window to a row.
Note: The result is a double. Casting it to an integer will give the row number.

Parameters
[in]north
[in]window
Returns
row id

Definition at line 129 of file window_map.c.

Referenced by G_align_window(), G_get_raster_sample_bilinear(), G_get_raster_sample_cubic(), and G_get_raster_sample_nearest().

int G_row_repeat_nomask ( int  fd,
int  row 
)

Loops rows until mismatch?.

This routine works fine if the mask is not set. It may give incorrect results with a mask, since the mask row may have a different repeat value. The issue can be fixed by doing it for the mask as well and using the smaller value.

Parameters
[in]fdfile descriptor
[in]rowstarting row
Returns
number of rows completed

Definition at line 344 of file window_map.c.

References fileinfo::C1, fileinfo::C2, count, fd, G__::fileinfo, and G__::window.

double G_row_to_northing ( double  row,
const struct Cell_head *  window 
)

Row to northing.

Converts a row relative to a window to a northing.
Note: row is a double:

  • row+0.0 will return the northing for the northern edge of the row.
  • row+0.5 will return the northing for the center of the row.
  • row+1.0 will return the northing for the southern edge of the row.
    Note: The result is a double. Casting it to an int will give the column number.
Parameters
[in]row
[in]window
Returns
north coordinate

Definition at line 223 of file window_map.c.

Referenced by G_align_window().

int G_window_cols ( void  )

Number of columns in active window.

These routines return the number of rows and columns (respectively) in the active module region. Before raster maps can be read or written, it is necessary to known how many rows and columns are in the active region. For example:

int nrows, cols;
int row, col;
nrows = G_window_rows( );
ncols = G_window_cols( );
for (row = 0; row < nrows; row++)
{
<i>read</i> row ...
for (col = 0; col < ncols; col++)
{
process col ...
}
}
Returns
number of columns

Definition at line 306 of file window_map.c.

References G__init_window(), and G__::window.

Referenced by G_allocate_c_raster_buf(), G_allocate_cell_buf(), G_allocate_d_raster_buf(), G_allocate_f_raster_buf(), G_allocate_null_buf(), G_allocate_raster_buf(), G_get_raster_sample_bilinear(), G_get_raster_sample_cubic(), G_get_raster_sample_nearest(), G_zero_cell_buf(), G_zero_raster_buf(), and IL_output_2d().

int G_window_rows ( void  )

Number of rows in active window.

This routine returns the number of rows in the active module window. Before raster files can be read or written, it is necessary to known how many rows are in the active window. For example:

int nrows, cols;
int row, col;
nrows = G_window_rows( );
ncols = G_window_cols( );
for (row = 0; row < nrows; row++)
{
<i>read</i> row ...
for (col = 0; col < ncols; col++)
{
process col ...
}
}
Returns
number of rows

Definition at line 273 of file window_map.c.

References G__init_window(), and G__::window.

Referenced by G_get_raster_sample_bilinear(), G_get_raster_sample_cubic(), G_get_raster_sample_nearest(), and IL_output_2d().