GRASS GIS 8 Programmer's Manual
8.5.0dev(2024)-03675b0323
|
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"
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... | |
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.
Definition in file raster/open.c.
#define FORMAT_FILE "f_format" |
Definition at line 28 of file raster/open.c.
#define NULL_FILE "null" |
Definition at line 29 of file raster/open.c.
#define NULLC_FILE "nullcmpr" |
Definition at line 31 of file raster/open.c.
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.
name | map name |
mapset | mapset where map name lives |
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().
int Rast__open_null_write | ( | const char * | name | ) |
Definition at line 763 of file raster/open.c.
References _, G_fatal_error(), G_find_raster2(), G_mapset(), G_store(), G_unqualified_name(), GMAPSET_MAX, GNAME_MAX, fileinfo::mapset, name, and Rast__init().
int Rast__open_old | ( | const char * | name, |
const char * | mapset | ||
) |
Lower level function, open cell files, supercell files, and the MASK file.
Actions:
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().
name | map name |
mapset | mapset of cell file to be opened |
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().
int Rast_get_cell_format | ( | CELL | v | ) |
Get cell value format.
v | cell |
Definition at line 480 of file raster/open.c.
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
fd | file descriptor |
Definition at line 932 of file raster/open.c.
References R__::fileinfo, and fileinfo::map_type.
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.
name | map name |
mapset | mapset name |
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.
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
name | map name |
mapset | mapset where map name lives |
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().
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.
name | map name |
Definition at line 418 of file raster/open.c.
int Rast_open_c_new_uncompressed | ( | const char * | name | ) |
Opens a new cell file in a database (uncompressed)
See also Rast_open_new().
name | map name |
Definition at line 433 of file raster/open.c.
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().
name | map name |
Definition at line 507 of file raster/open.c.
int Rast_open_fp_new_uncompressed | ( | const char * | name | ) |
Opens new fcell file in a database (uncompressed)
See Rast_open_fp_new() for details.
name | map name |
Definition at line 521 of file raster/open.c.
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:
On CELL_TYPE calls Rast_open_new() otherwise Rast_open_fp_new().
name | map name |
wr_type | raster data type |
Definition at line 1013 of file raster/open.c.
int Rast_open_new_uncompressed | ( | const char * | name, |
RASTER_MAP_TYPE | wr_type | ||
) |
Opens a new raster map (uncompressed)
See Rast_open_new().
name | map name |
wr_type | raster data type |
Definition at line 1028 of file raster/open.c.
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.
name | map name |
mapset | mapset name where raster map name lives |
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().
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
n | format |
Definition at line 463 of file raster/open.c.
References R__::nbytes.
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.
type | raster data type |
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().
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.
fd | file descriptor (cell file) |
q | pointer to Quant structure |
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.
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.
flag | flag indicator |
Definition at line 446 of file raster/open.c.
References R__::want_histogram.