78static void get_cond(
char **,
char *,
DCELL);
79static int get_fmt(
char **,
char *,
int *);
80static int cmp(
const void *,
const void *);
82static void write_cats(
const char *
element,
const char *
name,
84static CELL read_cats(
const char *
element,
const char *
name,
const char *mapset,
107 switch (read_cats(
"cats",
name, mapset,
pcats, 1)) {
109 G_warning(
_(
"Category support for <%s@%s> missing"),
name, mapset);
112 G_warning(
_(
"Category support for <%s@%s> invalid"),
name, mapset);
143 switch (read_cats(
"dig_cats",
name, mapset,
pcats, 1)) {
145 G_warning(
_(
"Category support for vector map <%s@%s> missing"),
name,
149 G_warning(
_(
"Category support for vector map <%s@%s> invalid"),
name,
185static CELL read_cats(
const char *
element,
const char *
name,
const char *mapset,
204 if (
G_getl(buff,
sizeof buff, fd) == 0)
207 if (
sscanf(buff,
"# %ld", &num) == 1)
209 else if (
sscanf(buff,
"%ld", &num) == 1)
220 if (
G_getl(buff,
sizeof(buff), fd) == 0)
231 float m1, a1, m2, a2;
233 if (
G_getl(fmt,
sizeof(fmt), fd) == 0)
236 if (
G_getl(buff,
sizeof(buff), fd) == 0)
238 if (
sscanf(buff,
"%f %f %f %f", &m1, &a1, &m2, &a2) != 4)
247 if (
G_getl(buff,
sizeof(buff), fd) == 0)
253 if (
sscanf(buff,
"%1s", label) != 1)
265 else if (
sscanf(buff,
"%d:%[^\n]", &
cat1, label) >= 1)
267 else if (
sscanf(buff,
"%lf:%[^\n]", &
val1, label) >= 1)
397 static char label[1024];
405 snprintf(label,
sizeof(label),
"no data");
414 G_debug(5,
"Rast_get_cat(): val %lf found i %d", val, i);
418 return pcats->labels[i];
435 else if (*f ==
'?') {
441 else if (get_fmt(&f, fmt, &i)) {
473 for (i = 0; i <
pcats->ncats; i++)
563 while (ncols-- > 0) {
568 if (i >
pcats->ncats)
586 pcats->last_marked_rule = -1;
608 G_debug(3,
"last marked %d nrules %d\n",
pcats->last_marked_rule,
615 if (
pcats->marks[i]) {
625 pcats->last_marked_rule = i;
673 void *
rast2,
long *count,
685static int get_fmt(
char **f,
char *fmt,
int *i)
716 while (*
ff >=
'0' && *
ff <=
'9')
724static void get_cond(
char **f,
char *value,
DCELL val)
827 for (i = 0; i <
pcats->ncats; i++) {
847 len = (
pcats->nalloc + 256) *
sizeof(
char *);
850 if (len != (
int)len) {
870 len = (
pcats->nalloc + 256) *
sizeof(
int);
871 if (len != (
int)len) {
879 pcats->nalloc += 256;
940 write_cats(
"cats",
name, cats);
957 write_cats(
"dig_cats",
name, cats);
960static void write_cats(
const char *
element,
const char *
name,
974 fprintf(fd,
"# %ld categories\n", (
long)cats->
num);
981 fprintf(fd,
"%.2f %.2f %.2f %.2f\n", cats->
m1, cats->
a1, cats->
m2,
995 if ((cats->
fmt && cats->
fmt[0]) || (descr && descr[0])) {
1007 descr !=
NULL ? descr :
"");
1033 if (i >
pcats->ncats) {
1039 return pcats->labels[index];
1156 pcats->last_marked_rule = -1;
1224 if (
pcats->ncats > 0) {
1225 for (i = 0; i <
pcats->ncats; i++)
1270 return pcats->ncats;
1287 if (
pcats->ncats <= 1)
1290 ncats =
pcats->ncats;
1291 G_debug(3,
"Rast_sort_cats(): Copying to save cats buffer");
1296 for (i = 0; i < ncats; i++)
1301 for (i = 0; i < ncats; i++) {
1303 G_debug(4,
" Write sorted cats, pcats = %p pcats->labels = %p",
1313static int cmp(
const void *
aa,
const void *
bb)
1315 const int *a =
aa, *
b =
bb;
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
FILE * G_fopen_new(const char *, const char *)
Open a new database file.
void G_newlines_to_spaces(char *)
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
void G_trim_decimal(char *)
Removes trailing zeros from decimal number.
void G_strip(char *)
Removes all leading and trailing white space from string.
#define G_incr_void_ptr(ptr, size)
char * G_store(const char *)
Copy string to allocated memory.
int G_getl(char *, int, FILE *)
Gets a line of text from a file.
int G_debug(int, const char *,...) __attribute__((format(printf
const char * G_mapset(void)
Get current mapset name.
int Rast_is_null_value(const void *, RASTER_MAP_TYPE)
To check if a raster value is set to NULL.
CELL Rast_quant_get_cell_value(struct Quant *, DCELL)
Returns a CELL category for the floating-point value based on the quantization rules in q....
void Rast_quant_free(struct Quant *)
Resets and frees allocated memory.
void Rast_set_d_null_value(DCELL *, int)
To set a number of DCELL raster values to NULL.
void Rast_set_d_value(void *, DCELL, RASTER_MAP_TYPE)
Places a DCELL raster value.
void Rast_quant_add_rule(struct Quant *, DCELL, DCELL, CELL, CELL)
Adds a new rule to the set of quantization rules.
void Rast_get_range_min_max(const struct Range *, CELL *, CELL *)
Get range min and max.
size_t Rast_cell_size(RASTER_MAP_TYPE)
Returns size of a raster cell in bytes.
int Rast_read_range(const char *, const char *, struct Range *)
Read raster range (CELL)
void Rast_quant_get_ith_rule(const struct Quant *, int, DCELL *, DCELL *, CELL *, CELL *)
Returns the i'th quantization rule.
int Rast_map_is_fp(const char *, const char *)
Check if raster map is floating-point.
void Rast_quant_init(struct Quant *)
Initialize the structure.
#define Rast_is_d_null_value(dcellVal)
#define Rast_is_c_null_value(cellVal)
DCELL Rast_get_d_value(const void *, RASTER_MAP_TYPE)
Retrieves the value of given type from pointer p (DCELL)
int Rast_quant_nof_rules(const struct Quant *)
Returns the number of quantization rules defined.
void Rast_set_cats_fmt(const char *fmt, double m1, double a1, double m2, double a2, struct Categories *pcats)
Set category fmt (?)
int Rast_number_of_cats(struct Categories *pcats)
Get number of raster categories.
char * Rast_get_next_marked_d_cat(struct Categories *pcats, DCELL *rast1, DCELL *rast2, long *count)
Get next marked raster categories (DCELL)
char * Rast_get_next_marked_c_cat(struct Categories *pcats, CELL *rast1, CELL *rast2, long *count)
Get next marked raster categories (CELL)
void Rast_free_cats(struct Categories *pcats)
Free category structure memory.
char * Rast_get_next_marked_cat(struct Categories *pcats, void *rast1, void *rast2, long *count, RASTER_MAP_TYPE data_type)
Get next marked raster categories.
void Rast_rewind_cats(struct Categories *pcats)
Rewind raster categories.
void Rast_write_cats(const char *name, struct Categories *cats)
Write raster category file.
CELL Rast_get_max_c_cat(const char *name, const char *mapset)
Get the max category number.
int Rast_set_c_cat(const CELL *rast1, const CELL *rast2, const char *label, struct Categories *pcats)
Set a raster category label (CELL)
int Rast_set_d_cat(const DCELL *rast1, const DCELL *rast2, const char *label, struct Categories *pcats)
Set a raster category label (DCELL)
int Rast_read_vector_cats(const char *name, const char *mapset, struct Categories *pcats)
Read vector category file.
char * Rast_get_ith_d_cat(const struct Categories *pcats, int i, DCELL *rast1, DCELL *rast2)
Get category description (DCELL)
int Rast_sort_cats(struct Categories *pcats)
Sort categories.
char * Rast_get_f_cat(FCELL *rast, struct Categories *pcats)
Get a raster category label (FCELL)
int Rast_mark_cats(const void *rast_row, int ncols, struct Categories *pcats, RASTER_MAP_TYPE data_type)
Looks up the category label for each raster value (DCELL).
char * Rast_get_ith_cat(const struct Categories *pcats, int i, void *rast1, void *rast2, RASTER_MAP_TYPE data_type)
Get category description.
char * Rast_get_next_marked_f_cat(struct Categories *pcats, FCELL *rast1, FCELL *rast2, long *count)
Get next marked raster categories (FCELL)
int Rast_set_cat(const void *rast1, const void *rast2, const char *label, struct Categories *pcats, RASTER_MAP_TYPE data_type)
Set a raster category label.
char * Rast_get_cat(void *rast, struct Categories *pcats, RASTER_MAP_TYPE data_type)
Get a raster category label.
int Rast_set_f_cat(const FCELL *rast1, const FCELL *rast2, const char *label, struct Categories *pcats)
Set a raster category label (FCELL)
char * Rast_get_cats_title(const struct Categories *pcats)
Get title from category structure struct.
void Rast_copy_cats(struct Categories *pcats_to, const struct Categories *pcats_from)
Copy raster categories.
char * Rast_get_ith_c_cat(const struct Categories *pcats, int i, void *rast1, void *rast2)
Get category description (CELL)
void Rast_mark_d_cats(const DCELL *rast_row, int ncols, struct Categories *pcats)
Looks up the category label for each raster value (DCELL).
void Rast_unmark_cats(struct Categories *pcats)
Sets marks for all categories to 0.
int Rast_read_cats(const char *name, const char *mapset, struct Categories *pcats)
Read raster category file.
char * Rast_get_d_cat(DCELL *rast, struct Categories *pcats)
Get a raster category label (DCELL)
void Rast_write_vector_cats(const char *name, struct Categories *cats)
Write vector category file.
void Rast_mark_c_cats(const CELL *rast_row, int ncols, struct Categories *pcats)
Looks up the category label for each raster value (CELL).
void Rast_init_cats(const char *title, struct Categories *pcats)
Initialize category structure.
void Rast_set_cats_title(const char *title, struct Categories *pcats)
Set title in category structure.
char * Rast_get_c_cat(CELL *rast, struct Categories *pcats)
Get a raster category label (CELL)
void Rast_mark_f_cats(const FCELL *rast_row, int ncols, struct Categories *pcats)
Looks up the category label for each raster value (FCELL).
char * Rast_get_ith_f_cat(const struct Categories *pcats, int i, void *rast1, void *rast2)
Get category description (FCELL)