GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72274
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

#define LIST   struct Histogram_list

Function Documentation

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
cat,:category
count
histogram,:struct 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().

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

Extends histogram struct to accommodate a new value.

Parameters
cat,:category
count
histogram,:struct for histogram
Returns

Definition at line 410 of file histogram.c.

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

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

void Rast_free_histogram ( struct Histogram histogram)

Frees memory allocated for the histogram.

frees the memory allocated for the histogram

Parameters
histogram,:struct for histogram
Returns

Definition at line 211 of file histogram.c.

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

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
histogram,:struct for histogram
Returns
CELL

Definition at line 178 of file histogram.c.

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

Referenced by Rast_histogram_eq().

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
n,:nth element
histogram,:struct for histogram
Returns
count

Definition at line 195 of file histogram.c.

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

Referenced by Rast_histogram_eq().

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
histogram,:struct for histogram
Returns
1 if successful, -1 on fail

Definition at line 165 of file histogram.c.

References Histogram::num.

Referenced by Rast_histogram_eq().

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().

void Rast_make_histogram_cs ( struct Cell_stats statf,
struct Histogram histogram 
)

Creates histogram based on cell statistics.

Parameters
statf,:cell statistics
histogram,:raster histogram
Returns

Definition at line 141 of file histogram.c.

References cat, count, Rast_add_histogram(), Rast_init_histogram(), Rast_next_cell_stat(), Rast_rewind_cell_stats(), and Rast_sort_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
name,:name of map
mapset,:mapset that map belongs to
histogram,:struct for histogram
Returns
1 if successful, 0 if no histogram file,

Definition at line 44 of file histogram.c.

References _, cat, count, fclose(), fd, 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().

void Rast_remove_histogram ( const char *  name)

Removes the histogram.

Removes the histogram information associated with map layer "name"

Parameters
name,:name of map
Returns

Definition at line 344 of file histogram.c.

References G_remove_misc().

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
cat,:category
count
histogram,:struct 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().

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
histogram,:struct for histogram
Returns
0 if successful, 1 on fail

Definition at line 228 of file histogram.c.

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

Referenced by Rast_make_histogram_cs(), and Rast_read_histogram().

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
histogram,:struct 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.

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
name,:name of map
histogram,:struct for histogram
Returns
void

Definition at line 90 of file histogram.c.

References cat, count, fclose(), LIST, list, Histogram::list, and Histogram::num.

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

Writes the histogram based on cell statistics to file.

Parameters
name,:name of map
statf,:cell statistics
Returns
void

Definition at line 116 of file histogram.c.

References cat, count, fclose(), Rast_next_cell_stat(), and Rast_rewind_cell_stats().

void Rast_zero_histogram ( struct Histogram histogram)

Zero out histogram struct.

Parameters
histogram,:struct for histogram
Returns

Definition at line 426 of file histogram.c.

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