78 static void get_cond(
char **, 
char *, 
DCELL);
 
   79 static int get_fmt(
char **, 
char *, 
int *);
 
   80 static int cmp(
const void *, 
const void *);
 
   82 static void write_cats(
const char *
element, 
const char *
name,
 
   84 static 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,
 
  185 static CELL read_cats(
const char *
element, 
const char *
name, 
const char *mapset,
 
  195     if (strncmp(
element, 
"dig", 3) == 0)
 
  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)
 
  244     for (cat1 = 0;; cat1++) {
 
  247         if (
G_getl(buff, 
sizeof(buff), fd) == 0)
 
  253             if (sscanf(buff, 
"%1s", label) != 1)
 
  260                 sscanf(buff, 
"%lf:%lf:%[^\n]", &val1, &val2, label) == 3)
 
  263                      sscanf(buff, 
"%d:%d:%[^\n]", &cat1, &cat2, label) == 3)
 
  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];
 
  402     char fmt[30], value_str[30];
 
  405         snprintf(label, 
sizeof(label), 
"no data");
 
  414     G_debug(5, 
"Rast_get_cat(): val %lf found i %d", val, i);
 
  426     a[0] = (float)val * pcats->
m1 + pcats->
a1;
 
  427     a[1] = (
float)val * pcats->
m2 + pcats->
a2;
 
  435             else if (*f == 
'?') {
 
  437                 get_cond(&f, v = value_str, val);
 
  441             else if (get_fmt(&f, fmt, &i)) {
 
  442                 snprintf(v = value_str, 
sizeof(value_str), fmt, a[i]);
 
  473     for (i = 0; i < pcats->
ncats; i++)
 
  563     while (ncols-- > 0) {
 
  568         if (i > pcats->
ncats)
 
  615         if (pcats->
marks[i]) {
 
  673                                void *rast2, 
long *
count,
 
  685 static int get_fmt(
char **f, 
char *fmt, 
int *i)
 
  716     while (*
ff >= 
'0' && *
ff <= 
'9')
 
  724 static void get_cond(
char **f, 
char *value, 
DCELL val)
 
  827     for (i = 0; i < pcats->
ncats; i++) {
 
  829         if ((dtmp1 == *rast1 && dtmp2 == *rast2) ||
 
  830             (dtmp1 == *rast2 && dtmp2 == *rast1)) {
 
  847         len = (pcats->
nalloc + 256) * 
sizeof(
char *);
 
  850         if (len != (
int)len) { 
 
  870         len = (pcats->
nalloc + 256) * 
sizeof(
int);
 
  871         if (len != (
int)len) { 
 
  915 int Rast_set_cat(
const void *rast1, 
const void *rast2, 
const char *label,
 
  940     write_cats(
"cats", 
name, cats);
 
  957     write_cats(
"dig_cats", 
name, cats);
 
  960 static void write_cats(
const char *
element, 
const char *
name,
 
  967     char str1[100], str2[100];
 
  974     fprintf(fd, 
"# %ld categories\n", (
long)cats->
num);
 
  980     fprintf(fd, 
"%s\n", cats->
fmt != 
NULL ? cats->
fmt : 
"");
 
  981     fprintf(fd, 
"%.2f %.2f %.2f %.2f\n", cats->
m1, cats->
a1, cats->
m2,
 
  985     if (strncmp(
element, 
"dig", 3) == 0)
 
  995         if ((cats->
fmt && cats->
fmt[0]) || (descr && descr[0])) {
 
  997                 snprintf(str1, 
sizeof(str1), 
"%.10f", val1);
 
  999                 fprintf(fd, 
"%s:%s\n", str1, descr != 
NULL ? descr : 
"");
 
 1002                 snprintf(str1, 
sizeof(str1), 
"%.10f", val1);
 
 1004                 snprintf(str2, 
sizeof(str2), 
"%.10f", val2);
 
 1006                 fprintf(fd, 
"%s:%s:%s\n", str1, str2,
 
 1007                         descr != 
NULL ? descr : 
"");
 
 1033     if (i > pcats->
ncats) {
 
 1039     return pcats->
labels[index];
 
 1224     if (pcats->
ncats > 0) {
 
 1225         for (i = 0; i < pcats->
ncats; i++)
 
 1255     for (i = 0; i < pcats_from->
ncats; i++) {
 
 1270     return pcats->
ncats;
 
 1283     int *indexes, i, ncats;
 
 1287     if (pcats->
ncats <= 1)
 
 1290     ncats = pcats->
ncats;
 
 1291     G_debug(3, 
"Rast_sort_cats(): Copying to save cats buffer");
 
 1295     indexes = (
int *)
G_malloc(
sizeof(
int) * ncats);
 
 1296     for (i = 0; i < ncats; i++)
 
 1299     qsort(indexes, ncats, 
sizeof(
int), cmp);
 
 1301     for (i = 0; i < ncats; i++) {
 
 1303         G_debug(4, 
"  Write sorted cats, pcats = %p pcats->labels = %p",
 
 1304                 (
void *)pcats, (
void *)pcats->
labels);
 
 1313 static int cmp(
const void *aa, 
const void *bb)
 
 1315     const int *a = aa, *
b = bb;
 
 1316     DCELL min_rast1, min_rast2, max_rast1, max_rast2;
 
 1323     if (min_rast1 < min_rast2)
 
 1325     if (min_rast1 > min_rast2)
 
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
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
void G_newlines_to_spaces(char *)
const char * G_mapset(void)
Get current mapset name.
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)
int G_getl(char *, int, FILE *)
Gets a line of text from a file.
int G_debug(int, const char *,...) __attribute__((format(printf
char * G_store(const char *)
Copy string to allocated memory.
FILE * G_fopen_new(const char *, const char *)
Open a new database file.
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 (?)
char * Rast_get_cats_title(const struct Categories *pcats)
Get title from category structure struct.
char * Rast_get_next_marked_f_cat(struct Categories *pcats, FCELL *rast1, FCELL *rast2, long *count)
Get next marked raster categories (FCELL)
int Rast_number_of_cats(struct Categories *pcats)
Get number of raster categories.
char * Rast_get_c_cat(CELL *rast, struct Categories *pcats)
Get a raster category label (CELL)
char * Rast_get_d_cat(DCELL *rast, struct Categories *pcats)
Get a raster category label (DCELL)
void Rast_free_cats(struct Categories *pcats)
Free category structure memory.
char * Rast_get_cat(void *rast, struct Categories *pcats, RASTER_MAP_TYPE data_type)
Get a raster category label.
void Rast_rewind_cats(struct Categories *pcats)
Rewind raster categories.
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_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.
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)
char * Rast_get_ith_f_cat(const struct Categories *pcats, int i, void *rast1, void *rast2)
Get category description (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_d_cat(const struct Categories *pcats, int i, DCELL *rast1, DCELL *rast2)
Get category description (DCELL)
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_next_marked_c_cat(struct Categories *pcats, CELL *rast1, CELL *rast2, long *count)
Get next marked raster categories (CELL)
int Rast_set_f_cat(const FCELL *rast1, const FCELL *rast2, const char *label, struct Categories *pcats)
Set a raster category label (FCELL)
void Rast_copy_cats(struct Categories *pcats_to, const struct Categories *pcats_from)
Copy raster categories.
char * Rast_get_next_marked_d_cat(struct Categories *pcats, DCELL *rast1, DCELL *rast2, long *count)
Get next marked raster categories (DCELL)
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.
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).
char * Rast_get_ith_cat(const struct Categories *pcats, int i, void *rast1, void *rast2, RASTER_MAP_TYPE data_type)
Get category description.
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.
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_c_cat(const struct Categories *pcats, int i, void *rast1, void *rast2)
Get category description (CELL)