GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72105
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

#define FORMAT_FILE   "f_format"

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

Referenced by Rast__check_fp_type().

#define NULL_FILE   "null"

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

Referenced by Rast__open_old().

#define NULLC_FILE   "nullcmpr"

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

Referenced by Rast__open_old().

Function Documentation

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 922 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, and NULL.

Referenced by Rast_map_type().

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, fileinfo::cellhd, close(), Cell_head::cols, Cell_head::compressed, fileinfo::cur_row, fileinfo::data, fileinfo::data_fd, DCELL_TYPE, FCELL_TYPE, fd, R__::fileinfo, Cell_head::format, G_check_compressor(), G_compressor_name(), G_fatal_error(), G_find_raster2(), G_free(), G_fully_qualified_name(), G_open_old(), G_open_old_misc(), G_projection_name(), G_store(), G_unqualified_name(), fileinfo::gdal, GMAPSET_MAX, GNAME_MAX, fileinfo::io_error, fileinfo::map_type, Reclass::mapset, fileinfo::mapset, name, Reclass::name, fileinfo::name, fileinfo::nbytes, NULL, fileinfo::null_bits, fileinfo::null_cur_row, fileinfo::null_fd, NULL_FILE, fileinfo::null_file_exists, fileinfo::null_row_ptr, NULLC_FILE, fileinfo::open_mode, OPEN_OLD, Cell_head::proj, fileinfo::quant, Rast__allocate_null_bits(), Rast__check_format(), Rast__create_window_mapping(), Rast__init(), Rast__read_null_row_ptrs(), Rast_get_cellhd(), Rast_get_gdal_link(), Rast_get_reclass(), Rast_map_type(), Rast_read_quant(), R__::rd_window, fileinfo::reclass, fileinfo::reclass_flag, Cell_head::rows, XDR_DOUBLE_NBYTES, XDR_FLOAT_NBYTES, and Cell_head::zone.

Referenced by Rast__check_for_auto_masking(), and Rast_open_old().

int Rast_get_cell_format ( CELL  v)

Get cell value format.

Parameters
vcell
Returns
cell format

Definition at line 462 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

Parameters
fdfile descriptor
Returns
raster data type

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

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

Referenced by Gs_get_cat_label(), I_compute_scatts(), N_read_rast_to_array_2d(), Rast_get_row_colors(), and Rast_map_to_img_str().

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 836 of file raster/open.c.

References _, G_fatal_error(), G_file_name(), G_find_raster2(), G_fully_qualified_name(), and GPATH_MAX.

Referenced by Gs_numtype(), gsd_put_legend(), and Rast_read_colors().

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 869 of file raster/open.c.

References _, CELL_TYPE, DCELL_TYPE, G_fatal_error(), G_file_name(), G_find_raster2(), GPATH_MAX, and Rast__check_fp_type().

Referenced by Rast__open_old(), Rast__quant_import(), Rast_get_gdal_link(), 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.

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

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

References CELL_TYPE, and OPEN_NEW_COMPRESSED.

Referenced by create_raster().

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 415 of file raster/open.c.

References CELL_TYPE, and OPEN_NEW_UNCOMPRESSED.

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 489 of file raster/open.c.

References R__::fp_type, and OPEN_NEW_COMPRESSED.

Referenced by IL_resample_output_2d().

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 503 of file raster/open.c.

References R__::fp_type, and OPEN_NEW_UNCOMPRESSED.

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 986 of file raster/open.c.

References OPEN_NEW_COMPRESSED.

Referenced by I_compute_scatts(), IL_output_2d(), and N_write_array_2d_to_rast().

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 1001 of file raster/open.c.

References OPEN_NEW_UNCOMPRESSED.

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 fd, Rast__check_for_auto_masking(), and Rast__open_old().

Referenced by Gs_get_cat_label(), Gs_loadmap_as_bitmap(), Gs_loadmap_as_char(), Gs_loadmap_as_float(), Gs_loadmap_as_int(), Gs_loadmap_as_short(), I_compute_scatts(), I_insert_patch_to_cat_rast(), IL_create_bitmask(), N_read_rast_to_array_2d(), open_band_files(), and Rast_map_to_img_str().

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 445 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.

Parameters
typeraster data type
Returns
void

Definition at line 809 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.

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

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

References _, Quant_table::cHigh, Quant_table::cLow, Quant_table::dHigh, Quant_table::dLow, fd, 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.

Parameters
flagflag indicator

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

References R__::want_histogram.