GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-602118adcc
raster/open.c File Reference

Raster Library - Open raster file. More...

#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <grass/config.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/glocale.h>
#include "R.h"
Include dependency graph for raster/open.c:

Go to the source code of this file.

Macros

#define FORMAT_FILE   "f_format"
 
#define NULL_FILE   "null"
 
#define NULLC_FILE   "nullcmpr"
 

Functions

int Rast_open_old (const char *name, const char *mapset)
 Open an existing integer raster map (cell) More...
 
int Rast__open_old (const char *name, const char *mapset)
 Lower level function, open cell files, supercell files, and the MASK file. More...
 
int Rast_open_c_new (const char *name)
 Opens a new cell file in a database (compressed) More...
 
int Rast_open_c_new_uncompressed (const char *name)
 Opens a new cell file in a database (uncompressed) More...
 
void Rast_want_histogram (int flag)
 Save histogram for newly create raster map (cell) More...
 
void Rast_set_cell_format (int n)
 Sets the format for subsequent opens on new integer cell files (uncompressed and random only). More...
 
int Rast_get_cell_format (CELL v)
 Get cell value format. More...
 
int Rast_open_fp_new (const char *name)
 Opens new fcell file in a database. More...
 
int Rast_open_fp_new_uncompressed (const char *name)
 Opens new fcell file in a database (uncompressed) More...
 
int Rast__open_null_write (const char *name)
 
void Rast_set_fp_type (RASTER_MAP_TYPE map_type)
 Set raster map floating-point data format. More...
 
int Rast_map_is_fp (const char *name, const char *mapset)
 Check if raster map is floating-point. More...
 
RASTER_MAP_TYPE Rast_map_type (const char *name, const char *mapset)
 Determine raster data type. More...
 
RASTER_MAP_TYPE Rast_get_map_type (int fd)
 Determine raster type from descriptor. More...
 
RASTER_MAP_TYPE Rast__check_fp_type (const char *name, const char *mapset)
 Determines whether the floating points cell file has double or float type. More...
 
int Rast_open_new (const char *name, RASTER_MAP_TYPE wr_type)
 Opens a new raster map. More...
 
int Rast_open_new_uncompressed (const char *name, RASTER_MAP_TYPE wr_type)
 Opens a new raster map (uncompressed) More...
 
void Rast_set_quant_rules (int fd, struct Quant *q)
 Sets quant translation rules for raster map opened for reading. More...
 

Detailed Description

Raster Library - Open raster file.

(C) 1999-2009 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
USACERL and many others

Definition in file raster/open.c.

Macro Definition Documentation

◆ FORMAT_FILE

#define FORMAT_FILE   "f_format"

Definition at line 28 of file raster/open.c.

◆ NULL_FILE

#define NULL_FILE   "null"

Definition at line 29 of file raster/open.c.

◆ NULLC_FILE

#define NULLC_FILE   "nullcmpr"

Definition at line 31 of file raster/open.c.

Function Documentation

◆ Rast__check_fp_type()

RASTER_MAP_TYPE Rast__check_fp_type ( const char *  name,
const char *  mapset 
)

Determines whether the floating points cell file has double or float type.

Parameters
namemap name
mapsetmapset where map name lives
Returns
raster type (fcell, dcell)

Definition at line 948 of file raster/open.c.

References _, DCELL_TYPE, FCELL_TYPE, FORMAT_FILE, G_fatal_error(), G_file_name_misc(), G_find_key_value(), G_find_raster2(), G_free_key_value(), G_fully_qualified_name(), G_read_key_value_file(), G_warning(), GPATH_MAX, name, and NULL.

Referenced by Rast_map_type().

◆ Rast__open_null_write()

int Rast__open_null_write ( const char *  name)

◆ Rast__open_old()

int Rast__open_old ( const char *  name,
const char *  mapset 
)

Lower level function, open cell files, supercell files, and the MASK file.

Actions:

  • opens the named cell file, following reclass reference if named layer is a reclass layer.
  • creates the required mapping between the data and the window for use by the get_map_row family of routines.

Diagnostics: Errors other than actual open failure will cause a diagnostic to be delivered through G_warning() open failure messages are left to the calling routine since the masking logic will want to issue a different warning.

Note: This routine does NOT open the MASK layer. If it did we would get infinite recursion. This routine is called to open the mask by Rast__check_for_auto_masking() which is called by Rast_open_old().

Parameters
namemap name
mapsetmapset of cell file to be opened
Returns
open file descriptor

Definition at line 152 of file raster/open.c.

References _, CELL_TYPE, Cell_head::compressed, DCELL_TYPE, FCELL_TYPE, Cell_head::format, G_check_compressor(), G_compressor_name(), G_fatal_error(), G_find_raster2(), G_fully_qualified_name(), G_open_old(), G_projection_name(), G_unqualified_name(), GMAPSET_MAX, GNAME_MAX, Reclass::mapset, Reclass::name, name, Cell_head::proj, Rast__init(), Rast_get_cellhd(), Rast_get_gdal_link(), Rast_get_reclass(), Rast_get_vrt(), Rast_map_type(), R__::rd_window, XDR_DOUBLE_NBYTES, XDR_FLOAT_NBYTES, and Cell_head::zone.

Referenced by Rast__check_for_auto_masking(), Rast_get_vrt_row(), and Rast_open_old().

◆ Rast_get_cell_format()

int Rast_get_cell_format ( CELL  v)

Get cell value format.

Parameters
vcell
Returns
cell format

Definition at line 480 of file raster/open.c.

◆ Rast_get_map_type()

RASTER_MAP_TYPE Rast_get_map_type ( int  fd)

Determine raster type from descriptor.

Determines if the raster map is floating point or integer. Returns DCELL_TYPE for double maps, FCELL_TYPE for float maps, CELL_TYPE for integer maps, -1 if error has occurred

Parameters
fdfile descriptor
Returns
raster data type

Definition at line 932 of file raster/open.c.

References R__::fileinfo, and fileinfo::map_type.

◆ Rast_map_is_fp()

int Rast_map_is_fp ( const char *  name,
const char *  mapset 
)

Check if raster map is floating-point.

Returns true (1) if raster map name in mapset is a floating-point dataset; false(0) otherwise.

Parameters
namemap name
mapsetmapset name
Returns
1 floating-point
0 int

Definition at line 861 of file raster/open.c.

References _, G_fatal_error(), G_file_name(), G_find_raster2(), G_fully_qualified_name(), GPATH_MAX, fileinfo::mapset, and name.

◆ Rast_map_type()

RASTER_MAP_TYPE Rast_map_type ( const char *  name,
const char *  mapset 
)

Determine raster data type.

Determines if the raster map is floating point or integer. Returns DCELL_TYPE for double maps, FCELL_TYPE for float maps, CELL_TYPE for integer maps, -1 if error has occurred

Parameters
namemap name
mapsetmapset where map name lives
Returns
raster data type

Definition at line 894 of file raster/open.c.

References _, CELL_TYPE, DCELL_TYPE, G_fatal_error(), G_file_name(), G_find_raster2(), GPATH_MAX, fileinfo::mapset, name, and Rast__check_fp_type().

Referenced by Rast__open_old(), Rast__quant_import(), Rast_read_fp_range(), Rast_read_range(), Rast_write_quant(), and Rast_write_range().

◆ Rast_open_c_new()

int Rast_open_c_new ( const char *  name)

Opens a new cell file in a database (compressed)

Opens a new cell file name in the current mapset for writing by Rast_put_row().

The file is created and filled with no data it is assumed that the new cell file is to conform to the current window.

The file must be written sequentially. Use Rast_open_new_random() for non sequential writes.

Note: the open actually creates a temporary file Rast_close() will move the temporary file to the cell file and write out the necessary support files (cellhd, cats, hist, etc.).

Diagnostics: warning message printed if open fails

Warning: calls to Rast_set_window() made after opening a new cell file may create confusion and should be avoided the new cell file will be created to conform to the window at the time of the open.

Parameters
namemap name
Returns
open file descriptor ( >= 0) if successful
negative integer if error

Definition at line 418 of file raster/open.c.

◆ Rast_open_c_new_uncompressed()

int Rast_open_c_new_uncompressed ( const char *  name)

Opens a new cell file in a database (uncompressed)

See also Rast_open_new().

Parameters
namemap name
Returns
open file descriptor ( >= 0) if successful
negative integer if error

Definition at line 433 of file raster/open.c.

◆ Rast_open_fp_new()

int Rast_open_fp_new ( const char *  name)

Opens new fcell file in a database.

Opens a new floating-point map name in the current mapset for writing. The type of the file (i.e. either double or float) is determined and fixed at this point. The default is FCELL_TYPE. In order to change this default

Use Rast_set_fp_type() where type is one of DCELL_TYPE or FCELL_TYPE.

See warnings and notes for Rast_open_new().

Parameters
namemap name
Returns
nonnegative file descriptor (int)

Definition at line 507 of file raster/open.c.

◆ Rast_open_fp_new_uncompressed()

int Rast_open_fp_new_uncompressed ( const char *  name)

Opens new fcell file in a database (uncompressed)

See Rast_open_fp_new() for details.

Parameters
namemap name
Returns
nonnegative file descriptor (int)

Definition at line 521 of file raster/open.c.

◆ Rast_open_new()

int Rast_open_new ( const char *  name,
RASTER_MAP_TYPE  wr_type 
)

Opens a new raster map.

Opens a new raster map of type wr_type

See warnings and notes for Rast_open_new().

Supported data types:

  • CELL_TYPE
  • FCELL_TYPE
  • DCELL_TYPE

On CELL_TYPE calls Rast_open_new() otherwise Rast_open_fp_new().

Parameters
namemap name
wr_typeraster data type
Returns
nonnegative file descriptor (int)

Definition at line 1013 of file raster/open.c.

◆ Rast_open_new_uncompressed()

int Rast_open_new_uncompressed ( const char *  name,
RASTER_MAP_TYPE  wr_type 
)

Opens a new raster map (uncompressed)

See Rast_open_new().

Parameters
namemap name
wr_typeraster data type
Returns
nonnegative file descriptor (int)

Definition at line 1028 of file raster/open.c.

◆ Rast_open_old()

int Rast_open_old ( const char *  name,
const char *  mapset 
)

Open an existing integer raster map (cell)

Opens the existing cell file name in the mapset for reading by Rast_get_row() with mapping into the current window.

This routine opens the raster map name in mapset for reading. A nonnegative file descriptor is returned if the open is successful. Otherwise a diagnostic message is printed and a negative value is returned. This routine does quite a bit of work. Since GRASS users expect that all raster maps will be resampled into the current region, the resampling index for the raster map is prepared by this routine after the file is opened. The resampling is based on the active module region (see also The_Region}. Preparation required for reading the various raster file formats (see Raster_File_Format for an explanation of the various raster file formats) is also done.

Diagnostics: warning message printed if open fails.

Parameters
namemap name
mapsetmapset name where raster map name lives
Returns
nonnegative file descriptor (int)

Definition at line 112 of file raster/open.c.

References name, Rast__check_for_auto_masking(), and Rast__open_old().

Referenced by IL_create_bitmask(), and open_band_files().

◆ Rast_set_cell_format()

void Rast_set_cell_format ( int  n)

Sets the format for subsequent opens on new integer cell files (uncompressed and random only).

Warning: subsequent put_row calls will only write n+1 bytes per cell. If the data requires more, the cell file will be written incorrectly (but with n+1 bytes per cell)

When writing float map: format is -1

Parameters
nformat

Definition at line 463 of file raster/open.c.

References R__::nbytes.

◆ Rast_set_fp_type()

void Rast_set_fp_type ( RASTER_MAP_TYPE  map_type)

Set raster map floating-point data format.

This controls the storage type for floating-point maps. It affects subsequent calls to G_open_fp_map_new(). The type must be one of FCELL_TYPE (float) or DCELL_TYPE (double). The use of this routine by applications is discouraged since its use would override user preferences.

Parameters
typeraster data type
Returns
void

Definition at line 833 of file raster/open.c.

References _, DCELL_TYPE, FCELL_TYPE, R__::fp_type, G_fatal_error(), fileinfo::map_type, and Rast__init().

◆ Rast_set_quant_rules()

void Rast_set_quant_rules ( int  fd,
struct Quant q 
)

Sets quant translation rules for raster map opened for reading.

Returned by Rast_open_old(). After calling this function, Rast_get_c_row() and Rast_get_c_row() will use rules defined by q (instead of using rules defined in map's quant file) to convert floats to ints.

Parameters
fdfile descriptor (cell file)
qpointer to Quant structure
Returns
void

Definition at line 1047 of file raster/open.c.

References _, Quant_table::cHigh, Quant_table::cLow, Quant_table::dHigh, Quant_table::dLow, R__::fileinfo, G_fatal_error(), Quant::nofRules, fileinfo::open_mode, OPEN_OLD, fileinfo::quant, Rast_quant_add_rule(), Rast_quant_get_neg_infinite_rule(), Rast_quant_get_pos_infinite_rule(), Rast_quant_init(), Rast_quant_set_neg_infinite_rule(), Rast_quant_set_pos_infinite_rule(), Rast_quant_truncate(), Quant::table, and Quant::truncate_only.

◆ Rast_want_histogram()

void Rast_want_histogram ( int  flag)

Save histogram for newly create raster map (cell)

If newly created cell files should have histograms, set flag=1 otherwise set flag=0. Applies to subsequent opens.

Parameters
flagflag indicator

Definition at line 446 of file raster/open.c.

References R__::want_histogram.