76static void get_cond(
char **,
char *,
DCELL);
77static int get_fmt(
char **,
char *,
int *);
78static int cmp(
const void *,
const void *);
80static void write_cats(
const char *
element,
const char *
name,
82static CELL read_cats(
const char *
element,
const char *
name,
const char *mapset,
105 switch (read_cats(
"cats",
name, mapset,
pcats, 1)) {
107 G_warning(
_(
"Category support for <%s@%s> missing"),
name, mapset);
110 G_warning(
_(
"Category support for <%s@%s> invalid"),
name, mapset);
141 switch (read_cats(
"dig_cats",
name, mapset,
pcats, 1)) {
143 G_warning(
_(
"Category support for vector map <%s@%s> missing"),
name,
147 G_warning(
_(
"Category support for vector map <%s@%s> invalid"),
name,
183static CELL read_cats(
const char *
element,
const char *
name,
const char *mapset,
202 if (
G_getl(buff,
sizeof buff, fd) == 0)
205 if (
sscanf(buff,
"# %ld", &num) == 1)
207 else if (
sscanf(buff,
"%ld", &num) == 1)
218 if (
G_getl(buff,
sizeof(buff), fd) == 0)
229 float m1, a1, m2, a2;
231 if (
G_getl(fmt,
sizeof(fmt), fd) == 0)
234 if (
G_getl(buff,
sizeof(buff), fd) == 0)
236 if (
sscanf(buff,
"%f %f %f %f", &m1, &a1, &m2, &a2) != 4)
245 if (
G_getl(buff,
sizeof(buff), fd) == 0)
251 if (
sscanf(buff,
"%1s", label) != 1)
263 else if (
sscanf(buff,
"%d:%[^\n]", &
cat1, label) >= 1)
265 else if (
sscanf(buff,
"%lf:%[^\n]", &
val1, label) >= 1)
395 static char label[1024];
403 snprintf(label,
sizeof(label),
"no data");
412 G_debug(5,
"Rast_get_cat(): val %lf found i %d", val, i);
416 return pcats->labels[i];
433 else if (*f ==
'?') {
439 else if (get_fmt(&f, fmt, &i)) {
471 for (i = 0; i <
pcats->ncats; i++)
561 while (ncols-- > 0) {
566 if (i >
pcats->ncats)
584 pcats->last_marked_rule = -1;
606 G_debug(3,
"last marked %d nrules %d\n",
pcats->last_marked_rule,
613 if (
pcats->marks[i]) {
623 pcats->last_marked_rule = i;
671 void *
rast2,
long *count,
683static int get_fmt(
char **f,
char *fmt,
int *i)
714 while (*
ff >=
'0' && *
ff <=
'9')
722static void get_cond(
char **f,
char *value,
DCELL val)
825 for (i = 0; i <
pcats->ncats; i++) {
845 len = (
pcats->nalloc + 256) *
sizeof(
char *);
848 if (len != (
int)len) {
868 len = (
pcats->nalloc + 256) *
sizeof(
int);
869 if (len != (
int)len) {
877 pcats->nalloc += 256;
938 write_cats(
"cats",
name, cats);
955 write_cats(
"dig_cats",
name, cats);
958static void write_cats(
const char *
element,
const char *
name,
972 fprintf(fd,
"# %ld categories\n", (
long)cats->
num);
979 fprintf(fd,
"%.2f %.2f %.2f %.2f\n", cats->
m1, cats->
a1, cats->
m2,
993 if ((cats->
fmt && cats->
fmt[0]) || (descr && descr[0])) {
1005 descr !=
NULL ? descr :
"");
1031 if (i >
pcats->ncats) {
1037 return pcats->labels[index];
1154 pcats->last_marked_rule = -1;
1222 if (
pcats->ncats > 0) {
1223 for (i = 0; i <
pcats->ncats; i++)
1268 return pcats->ncats;
1285 if (
pcats->ncats <= 1)
1288 ncats =
pcats->ncats;
1289 G_debug(3,
"Rast_sort_cats(): Copying to save cats buffer");
1294 for (i = 0; i < ncats; i++)
1299 for (i = 0; i < ncats; i++) {
1301 G_debug(4,
" Write sorted cats, pcats = %p pcats->labels = %p",
1311static int cmp(
const void *
aa,
const void *
bb)
1313 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)