17 #include <sys/types.h> 22 #include <grass/config.h> 23 #include <grass/gis.h> 24 #include <grass/raster.h> 25 #include <grass/glocale.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);
344 fcb->
data = (
unsigned char *)G_calloc(fcb->
cellhd.
cols, MAP_NBYTES);
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"));
int G_make_mapset_element(const char *p_element)
Create element in the current mapset.
int Rast__check_for_auto_masking(void)
Checks for auto masking.
#define OPEN_NEW_COMPRESSED
struct Cell_head rd_window
const char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key (case sensitive)
int Rast_quant_get_neg_infinite_rule(const struct Quant *q, DCELL *dLeft, CELL *c)
Returns in "dLeft" and "c" the rule values.
int Rast_get_reclass(const char *name, const char *mapset, struct Reclass *reclass)
Get reclass.
void G_free(void *buf)
Free allocated memory.
void Rast__create_window_mapping(int fd)
Create window mapping.
int Rast_open_fp_new(const char *name)
Opens new fcell file in a database.
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.
void Rast_quant_truncate(struct Quant *quant)
Sets the quant rules to perform simple truncation on floats.
void Rast_set_quant_rules(int fd, struct Quant *q)
Sets quant translation rules for raster map opened for reading.
2D/3D raster map header (used also for region)
void Rast_init_cell_stats(struct Cell_stats *s)
Initialize cell stats.
const char * G_projection_name(int n)
Get projection name.
char * G_compressor_name(int number)
void Rast_want_histogram(int flag)
Save histogram for newly create raster map (cell)
char * G_store(const char *s)
Copy string to allocated memory.
int G_unqualified_name(const char *name, const char *mapset, char *xname, char *xmapset)
Returns unqualified map name (without @ mapset)
char * G_tempfile(void)
Returns a temporary file name.
int Rast_open_fp_new_uncompressed(const char *name)
Opens new fcell file in a database (uncompressed)
int Rast_quant_get_pos_infinite_rule(const struct Quant *q, DCELL *dRight, CELL *c)
Returns in "dRight" and "c" the rule values.
unsigned char * null_bits
int format
Max number of bytes per raster data value minus 1 (raster header only)
struct R_vrt * Rast_get_vrt(const char *vname, const char *vmapset)
void Rast_quant_add_rule(struct Quant *q, DCELL dLow, DCELL dHigh, CELL cLow, CELL cHigh)
Adds a new rule to the set of quantization rules.
#define OPEN_NEW_UNCOMPRESSED
void G_free_key_value(struct Key_Value *kv)
Free allocated Key_Value structure.
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int G_open_old_misc(const char *dir, const char *element, const char *name, const char *mapset)
open a database file for reading
struct Cell_head wr_window
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
struct Key_Value * G_read_key_value_file(const char *file)
Read key/values pairs from file.
char * G_file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
int compressed
Compression mode (raster header only)
size_t Rast_cell_size(RASTER_MAP_TYPE data_type)
Returns size of a raster cell in bytes.
RASTER_MAP_TYPE Rast_map_type(const char *name, const char *mapset)
Determine raster data type.
void Rast_get_cellhd(const char *name, const char *mapset, struct Cell_head *cellhd)
Read the raster header.
struct GDAL_link * Rast_create_gdal_link(const char *name, RASTER_MAP_TYPE map_type)
Create GDAL settings for given raster map.
void Rast_init_range(struct Range *range)
Initialize range structure.
struct Quant_table * table
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)
#define XDR_DOUBLE_NBYTES
struct fileinfo * fileinfo
int Rast_read_quant(const char *name, const char *mapset, struct Quant *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.
int G_open_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
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.
int G_check_compressor(int number)
void Rast_quant_init(struct Quant *quant)
Initialize the structure.
char * G_fully_qualified_name(const char *name, const char *mapset)
Get fully qualified element name.
const char * G_find_raster2(const char *name, const char *mapset)
Find a raster map (look but don't touch)
int Rast_open_new(const char *name, RASTER_MAP_TYPE wr_type)
Opens a new raster map.
int Rast_map_is_fp(const char *name, const char *mapset)
Check if raster map is floating-point.
const char * G_mapset(void)
Get current mapset name.
char * G_file_name_misc(char *path, const char *dir, const char *element, const char *name, const char *mapset)
Builds full path names to GIS misc data files.
void G_zero(void *buf, int i)
Zero out a buffer, buf, of length i.
int Rast_open_old(const char *name, const char *mapset)
Open an existing integer raster map (cell)
unsigned char * Rast__allocate_null_bits(int cols)
Allocates memory for null bits.
void Rast_quant_set_pos_infinite_rule(struct Quant *q, DCELL dRight, CELL c)
Defines a rule for values "dRight" and larger.
int G_legal_filename(const char *s)
Check for legal database file name.
int rows
Number of rows for 2D data.
void G_warning(const char *msg,...)
Print a warning message to stderr.
void Rast_quant_set_neg_infinite_rule(struct Quant *q, DCELL dLeft, CELL c)
Defines a rule for values "dLeft" and smaller.
const char * G_find_file2(const char *element, const char *name, const char *mapset)
Searches for a file from the mapset search list or in a specified mapset. (look but don't touch) ...
int Rast__open_old(const char *name, const char *mapset)
Lower level function, open cell files, supercell files, and the MASK file.
void Rast_init_fp_range(struct FPRange *range)
Initialize fp range.
struct GDAL_link * Rast_get_gdal_link(const char *name, const char *mapset)
Get GDAL link settings for given raster map.
int Rast_get_cell_format(CELL v)
Get cell value format.