GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
histogram.c File Reference
#include <stdlib.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/glocale.h>
Include dependency graph for histogram.c:

Go to the source code of this file.

Macros

#define LIST   struct Histogram_list
 

Functions

void Rast_init_histogram (struct Histogram *histogram)
 initializes the histogram structure More...
 
int Rast_read_histogram (const char *name, const char *mapset, struct Histogram *histogram)
 read the histogram information More...
 
void Rast_write_histogram (const char *name, const struct Histogram *histogram)
 Writes the histogram information. More...
 
void Rast_write_histogram_cs (const char *name, struct Cell_stats *statf)
 Writes the histogram based on cell statistics to file. More...
 
void Rast_make_histogram_cs (struct Cell_stats *statf, struct Histogram *histogram)
 Creates histogram based on cell statistics. More...
 
int Rast_get_histogram_num (const struct Histogram *histogram)
 Sorts the histogram in ascending order by counts then category. More...
 
CELL Rast_get_histogram_cat (int n, const struct Histogram *histogram)
 Returns cat for the nth element in the histogram. More...
 
long Rast_get_histogram_count (int n, const struct Histogram *histogram)
 Returns count for the nth element in the histogram. More...
 
void Rast_free_histogram (struct Histogram *histogram)
 Frees memory allocated for the histogram. More...
 
int Rast_sort_histogram (struct Histogram *histogram)
 Sorts the histogram. More...
 
int Rast_sort_histogram_by_count (struct Histogram *histogram)
 Sorts the histogram by counts. More...
 
void Rast_remove_histogram (const char *name)
 Removes the histogram. More...
 
int Rast_add_histogram (CELL cat, long count, struct Histogram *histogram)
 adds count to the histogram value for cat More...
 
int Rast_set_histogram (CELL cat, long count, struct Histogram *histogram)
 sets the histogram value for cat to count More...
 
void Rast_extend_histogram (CELL cat, long count, struct Histogram *histogram)
 Extends histogram struct to accommodate a new value. More...
 
void Rast_zero_histogram (struct Histogram *histogram)
 Zero out histogram struct. More...
 

Macro Definition Documentation

◆ LIST

#define LIST   struct Histogram_list

Function Documentation

◆ Rast_add_histogram()

int Rast_add_histogram ( CELL  cat,
long  count,
struct Histogram histogram 
)

adds count to the histogram value for cat

adds count to the histogram value for cat

Parameters
catcategory
count
histogramstruct for histogram
Returns
0 if successful, 1 on fail

Definition at line 360 of file histogram.c.

References Histogram::Histogram_list::cat, count, Histogram::Histogram_list::count, Histogram::list, Histogram::num, and Rast_extend_histogram().

Referenced by Rast_make_histogram_cs().

◆ Rast_extend_histogram()

void Rast_extend_histogram ( CELL  cat,
long  count,
struct Histogram histogram 
)

Extends histogram struct to accommodate a new value.

Parameters
catcategory
count
histogramstruct for histogram
Returns

Definition at line 410 of file histogram.c.

References Histogram::Histogram_list::cat, count, Histogram::Histogram_list::count, G_realloc, LIST, Histogram::list, and Histogram::num.

Referenced by Rast_add_histogram(), Rast_read_histogram(), and Rast_set_histogram().

◆ Rast_free_histogram()

void Rast_free_histogram ( struct Histogram histogram)

Frees memory allocated for the histogram.

frees the memory allocated for the histogram

Parameters
histogramstruct for histogram
Returns

Definition at line 211 of file histogram.c.

References G_free(), Histogram::list, NULL, and Histogram::num.

◆ Rast_get_histogram_cat()

CELL Rast_get_histogram_cat ( int  n,
const struct Histogram histogram 
)

Returns cat for the nth element in the histogram.

Returns cat for the nth element in the histogram

Parameters
histogramstruct for histogram
Returns
CELL

Definition at line 178 of file histogram.c.

References Histogram::Histogram_list::cat, Histogram::list, and Histogram::num.

◆ Rast_get_histogram_count()

long Rast_get_histogram_count ( int  n,
const struct Histogram histogram 
)

Returns count for the nth element in the histogram.

Returns count for the nth element in the histogram

Parameters
nnth element
histogramstruct for histogram
Returns
count

Definition at line 195 of file histogram.c.

References Histogram::Histogram_list::count, Histogram::list, and Histogram::num.

◆ Rast_get_histogram_num()

int Rast_get_histogram_num ( const struct Histogram histogram)

Sorts the histogram in ascending order by counts then category.

Sorts the histogram in ascending order by counts then category. No combining is done.

Parameters
histogramstruct for histogram
Returns
1 if successful, -1 on fail

Definition at line 165 of file histogram.c.

References Histogram::num.

◆ Rast_init_histogram()

void Rast_init_histogram ( struct Histogram histogram)

initializes the histogram structure

initializes the histogram structure for calls to Rast_set_histogram() and Rast_add_histogram()

Parameters
histogram
Returns

Definition at line 23 of file histogram.c.

References Histogram::list, NULL, and Histogram::num.

Referenced by Rast_make_histogram_cs(), and Rast_read_histogram().

◆ Rast_make_histogram_cs()

void Rast_make_histogram_cs ( struct Cell_stats statf,
struct Histogram histogram 
)

Creates histogram based on cell statistics.

Parameters
statfcell statistics
histogramraster histogram
Returns

Definition at line 141 of file histogram.c.

References count, Rast_add_histogram(), Rast_init_histogram(), Rast_next_cell_stat(), Rast_rewind_cell_stats(), and Rast_sort_histogram().

◆ Rast_read_histogram()

int Rast_read_histogram ( const char *  name,
const char *  mapset,
struct Histogram histogram 
)

read the histogram information

Reads the histogram information associated with map layer "map" in mapset "mapset" into the structure "histogram".

note: a warning message is printed if the file is missing or incorrect

Parameters
namename of map
mapsetmapset that map belongs to
histogramstruct for histogram
Returns
1 if successful, 0 if no histogram file,

Definition at line 44 of file histogram.c.

References _, count, G_fatal_error(), G_find_file2_misc(), G_fopen_old_misc(), G_warning(), NULL, Histogram::num, Rast_extend_histogram(), Rast_init_histogram(), and Rast_sort_histogram().

◆ Rast_remove_histogram()

void Rast_remove_histogram ( const char *  name)

Removes the histogram.

Removes the histogram information associated with map layer "name"

Parameters
namename of map
Returns

Definition at line 344 of file histogram.c.

References G_remove_misc().

◆ Rast_set_histogram()

int Rast_set_histogram ( CELL  cat,
long  count,
struct Histogram histogram 
)

sets the histogram value for cat to count

sets the histogram value for cat to count

Parameters
catcategory
count
histogramstruct for histogram
Returns
0 if successful, 1 on fail

Definition at line 386 of file histogram.c.

References Histogram::Histogram_list::cat, count, Histogram::Histogram_list::count, Histogram::list, Histogram::num, and Rast_extend_histogram().

◆ Rast_sort_histogram()

int Rast_sort_histogram ( struct Histogram histogram)

Sorts the histogram.

Sorts the histogram in ascending order by category, combining (by adding) elements that have the same category.

Parameters
histogramstruct for histogram
Returns
0 if successful, 1 on fail

Definition at line 228 of file histogram.c.

Referenced by Rast_make_histogram_cs(), and Rast_read_histogram().

◆ Rast_sort_histogram_by_count()

int Rast_sort_histogram_by_count ( struct Histogram histogram)

Sorts the histogram by counts.

Sorts the histogram in ascending order by counts then category. No combining is done.

Parameters
histogramstruct for histogram
Returns
0 if successful, 1 on fail

Definition at line 288 of file histogram.c.

References LIST, list, Histogram::list, and Histogram::num.

◆ Rast_write_histogram()

void Rast_write_histogram ( const char *  name,
const struct Histogram histogram 
)

Writes the histogram information.

Writes the histogram information associated with map layer "name"

Parameters
namename of map
histogramstruct for histogram
Returns
void

Definition at line 90 of file histogram.c.

References LIST, and list.

◆ Rast_write_histogram_cs()

void Rast_write_histogram_cs ( const char *  name,
struct Cell_stats statf 
)

Writes the histogram based on cell statistics to file.

Parameters
namename of map
statfcell statistics
Returns
void

Definition at line 116 of file histogram.c.

References count.

◆ Rast_zero_histogram()

void Rast_zero_histogram ( struct Histogram histogram)

Zero out histogram struct.

Parameters
histogramstruct for histogram
Returns

Definition at line 426 of file histogram.c.

References Histogram::Histogram_list::count, Histogram::list, and Histogram::num.