17 #include <sys/types.h> 28 #define FORMAT_FILE "f_format" 29 #define NULL_FILE "null" 31 #define NULLC_FILE "nullcmpr" 33 static int new_fileinfo(
void)
36 int newsize = oldsize;
39 for (i = 0; i < oldsize; i++)
54 for (i = oldsize; i < newsize; i++) {
84 static int open_raster_new(
const char *
name,
int open_mode,
158 const char *r_mapset;
183 switch (reclass_flag) {
189 r_name = reclass.
name;
190 r_mapset = reclass.
mapset;
192 G_fatal_error(
_(
"Unable to open raster map <%s@%s> since it is a reclass " 193 "of raster map <%s@%s> which does not exist"),
194 name, mapset, r_name, r_mapset);
197 G_fatal_error(
_(
"Error reading reclass file for raster map <%s>"),
214 CELL_nbytes = cellhd.
format + 1;
216 G_fatal_error(
_(
"Raster map <%s@%s>: format field in header file invalid"),
239 G_fatal_error(
_(
"Raster map <%s> is in different projection than current region. " 240 "Found <%s>, should be <%s>."),
246 G_fatal_error(
_(
"Raster map <%s> is in different zone (%d) than current region (%d)"),
250 if (MAP_TYPE ==
CELL_TYPE && (
unsigned int)CELL_nbytes >
sizeof(
CELL))
251 G_fatal_error(
_(
"Raster map <%s>: bytes per cell (%d) too large"),
257 INTERN_SIZE =
sizeof(
FCELL);
262 INTERN_SIZE =
sizeof(
DCELL);
267 INTERN_SIZE =
sizeof(
CELL);
268 MAP_NBYTES = CELL_nbytes;
278 G_fatal_error(
_(
"Raster map <%s@%s> is a GDAL link but GRASS is compiled without GDAL support"),
287 cell_fd =
G_open_old(cell_dir, r_name, r_mapset);
290 cell_dir, r_name, r_mapset);
477 for (i = 0; i <
sizeof(
CELL); i++)
480 return sizeof(
CELL) - 1;
519 static int open_raster_new_gdal(
char *map,
char *mapset,
588 const char *cell_dir;
612 G_fatal_error(
_(
"Raster map <%s> is not in the current mapset (%s)"),
623 return open_raster_new_gdal(map, mapset, map_type);
628 cell_fd = creat(tempname, 0666);
707 fcb->
null_fd = creat(tempname, 0666);
764 G_fatal_error(
_(
"Raster map <%s> does not exist in the current mapset (%s)"),
768 G_fatal_error(
_(
"Raster map <%s> is not in the current mapset (%s)"),
776 G_zero(fcb,
sizeof(*fcb));
785 fcb->
null_fd = creat(tempname, 0666);
830 G_fatal_error(
_(
"Rast_set_fp_type(): can only be called with FCELL_TYPE or DCELL_TYPE"));
858 if (access(path, 0) == 0)
862 if (access(path, 0) == 0)
887 if (mapset && *mapset)
896 if (access(path, 0) == 0)
901 if (access(path, 0) == 0)
937 const char *str, *str1;
948 if (access(path, 0) != 0)
954 if (strcmp(str,
"double") == 0)
956 else if (strcmp(str,
"float") == 0)
960 G_fatal_error(
_(
"Invalid type: field '%s' in file '%s'"), str, path);
969 if (strcmp(str1,
"xdr") != 0)
970 G_warning(
_(
"Raster map <%s> is not xdr: byte_order: %s"),
1040 "raster maps opened for reading"));
#define OPEN_NEW_COMPRESSED
struct Cell_head rd_window
char * G_file_name_misc(char *, const char *, const char *, const char *, const char *)
Builds full path names to GIS misc data files.
const char * G_find_file2(const char *, const char *, const char *)
Searches for a file from the mapset search list or in a specified mapset. (look but don't touch) ...
char * G_file_name(char *, const char *, const char *, const char *)
Builds full path names to GIS data files.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int Rast_open_fp_new(const char *name)
Opens new fcell file in a database.
struct Key_Value * G_read_key_value_file(const char *)
Read key/values pairs from file.
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.
int G_check_compressor(int)
void Rast_set_quant_rules(int fd, struct Quant *q)
Sets quant translation rules for raster map opened for reading.
struct GDAL_link * Rast_get_gdal_link(const char *, const char *)
Get GDAL link settings for given raster map.
int Rast_quant_get_pos_infinite_rule(const struct Quant *, DCELL *, CELL *)
Returns in "dRight" and "c" the rule values.
2D/3D raster map header (used also for region)
int Rast_read_quant(const char *, const char *, struct Quant *)
Reads quantization rules for name in mapset and stores them in the quantization structure. If the map is in another mapset, first checks for quant2 table for this map in current mapset.
struct GDAL_link * Rast_create_gdal_link(const char *, RASTER_MAP_TYPE)
Create GDAL settings for given raster map.
void Rast_want_histogram(int flag)
Save histogram for newly create raster map (cell)
int G_unqualified_name(const char *, const char *, char *, char *)
Returns unqualified map name (without @ mapset)
void G_free(void *)
Free allocated memory.
int Rast_open_fp_new_uncompressed(const char *name)
Opens new fcell file in a database (uncompressed)
struct R_vrt * Rast_get_vrt(const char *, const char *)
unsigned char * null_bits
int format
Max number of bytes per raster data value minus 1 (raster header only)
void Rast_quant_init(struct Quant *)
Initialize the structure.
#define OPEN_NEW_UNCOMPRESSED
char * G_compressor_name(int)
struct Cell_head wr_window
unsigned char * Rast__allocate_null_bits(int)
Allocates memory for null bits.
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
int G_open_old_misc(const char *, const char *, const char *, const char *)
open a database file for reading
int G_open_old(const char *, const char *, const char *)
Open a database file for reading.
int compressed
Compression mode (raster header only)
RASTER_MAP_TYPE Rast_map_type(const char *name, const char *mapset)
Determine raster data type.
void Rast_init_range(struct Range *)
Initialize range structure.
int Rast__read_null_row_ptrs(int, int)
struct Quant_table * table
char * G_fully_qualified_name(const char *, const char *)
Get fully qualified element name.
const char * G_projection_name(int)
Get projection name.
size_t Rast_cell_size(RASTER_MAP_TYPE)
Returns size of a raster cell in bytes.
char * G_tempfile(void)
Returns a temporary file name.
int Rast_open_c_new_uncompressed(const char *name)
Opens a new cell file in a database (uncompressed)
void Rast_set_cell_format(int n)
Sets the format for subsequent opens on new integer cell files (uncompressed and random only)...
int zone
Projection zone (UTM)
void Rast_set_fp_type(RASTER_MAP_TYPE map_type)
Set raster map floating-point data format.
int Rast_open_c_new(const char *name)
Opens a new cell file in a database (compressed)
int Rast_quant_get_neg_infinite_rule(const struct Quant *, DCELL *, CELL *)
Returns in "dLeft" and "c" the rule values.
int G_legal_filename(const char *)
Check for legal database file name.
int Rast_get_reclass(const char *, const char *, struct Reclass *)
Get reclass.
#define XDR_DOUBLE_NBYTES
void Rast_quant_set_pos_infinite_rule(struct Quant *, DCELL, CELL)
Defines a rule for values "dRight" and larger.
struct fileinfo * fileinfo
void Rast__create_window_mapping(int)
Create window mapping.
int Rast__check_format(int)
int Rast__write_row_ptrs(int)
int Rast__open_null_write(const char *name)
int Rast_open_new_uncompressed(const char *name, RASTER_MAP_TYPE wr_type)
Opens a new raster map (uncompressed)
RASTER_MAP_TYPE Rast_get_map_type(int fd)
Determine raster type from descriptor.
int cols
Number of columns for 2D data.
void Rast_get_cellhd(const char *, const char *, struct Cell_head *)
Read the raster header.
void Rast_quant_add_rule(struct Quant *, DCELL, DCELL, CELL, CELL)
Adds a new rule to the set of quantization rules.
const char * G_mapset(void)
Get current mapset name.
void Rast_init_cell_stats(struct Cell_stats *)
Initialize cell stats.
void Rast_init_fp_range(struct FPRange *)
Initialize fp range.
void G_zero(void *, int)
Zero out a buffer, buf, of length i.
void G_warning(const char *,...) __attribute__((format(printf
int G_make_mapset_element(const char *)
Create element in the current mapset.
int Rast_open_new(const char *name, RASTER_MAP_TYPE wr_type)
Opens a new raster map.
const char * G_find_raster2(const char *, const char *)
Find a raster map (look but don't touch)
void Rast_quant_set_neg_infinite_rule(struct Quant *, DCELL, CELL)
Defines a rule for values "dLeft" and smaller.
char * G_store(const char *)
Copy string to allocated memory.
int Rast_map_is_fp(const char *name, const char *mapset)
Check if raster map is floating-point.
int Rast_open_old(const char *name, const char *mapset)
Open an existing integer raster map (cell)
int Rast__write_null_row_ptrs(int, int)
int Rast__check_for_auto_masking(void)
Checks for auto masking.
int rows
Number of rows for 2D data.
int Rast__open_old(const char *name, const char *mapset)
Lower level function, open cell files, supercell files, and the MASK file.
void Rast_quant_truncate(struct Quant *)
Sets the quant rules to perform simple truncation on floats.
void G_free_key_value(struct Key_Value *)
Free allocated Key_Value structure.
int Rast_get_cell_format(CELL v)
Get cell value format.
const char * G_find_key_value(const char *, const struct Key_Value *)
Find given key (case sensitive)