GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71924
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cell_stats.c File Reference

Raster Library - Raster cell statistics. More...

#include <stdlib.h>
#include <grass/gis.h>
#include <grass/raster.h>
Include dependency graph for cell_stats.c:

Go to the source code of this file.

Macros

#define INCR   10
 
#define SHIFT   6
 
#define NODE   struct Cell_stats_node
 

Functions

void Rast_init_cell_stats (struct Cell_stats *s)
 Initialize cell stats. More...
 
int Rast_update_cell_stats (const CELL *cell, int n, struct Cell_stats *s)
 Add data to cell stats. More...
 
int Rast_find_cell_stat (CELL cat, long *count, const struct Cell_stats *s)
 Random query of cell stats. More...
 
int Rast_rewind_cell_stats (struct Cell_stats *s)
 Reset/rewind cell stats. More...
 
int Rast_next_cell_stat (CELL *cat, long *count, struct Cell_stats *s)
 Retrieve sorted cell stats. More...
 
void Rast_get_stats_for_null_value (long *count, const struct Cell_stats *s)
 Get number of null values. More...
 
void Rast_free_cell_stats (struct Cell_stats *s)
 Free cell stats structure. More...
 

Detailed Description

Raster Library - Raster cell statistics.

(C) 2001-2009 GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Original author CERL

Definition in file cell_stats.c.

Macro Definition Documentation

#define INCR   10

Definition at line 19 of file cell_stats.c.

Referenced by Rast_init_cell_stats(), and Rast_update_cell_stats().

#define NODE   struct Cell_stats_node

Definition at line 24 of file cell_stats.c.

Referenced by Rast_init_cell_stats(), and Rast_update_cell_stats().

#define SHIFT   6

Definition at line 20 of file cell_stats.c.

Referenced by Rast_find_cell_stat(), Rast_next_cell_stat(), and Rast_update_cell_stats().

Function Documentation

int Rast_find_cell_stat ( CELL  cat,
long *  count,
const struct Cell_stats s 
)

Random query of cell stats.

This routine allows a random query of the Cell_stats structure. The count associated with the raster value cat is set. The routine returns 1 if cat was found in the structure, 0 otherwise.

Allow finding the count for the NULL-value.

Parameters
catraster value
[out]countcount
spointer to Cell_stats structure which holds cell stats info
Returns
1 if found
0 if not found

Definition at line 190 of file cell_stats.c.

References cat, Cell_stats::Cell_stats_node::count, Cell_stats::Cell_stats_node::idx, Cell_stats::Cell_stats_node::left, Cell_stats::N, Cell_stats::node, Cell_stats::null_data_count, Rast_is_c_null_value(), Cell_stats::Cell_stats_node::right, and SHIFT.

void Rast_free_cell_stats ( struct Cell_stats s)

Free cell stats structure.

The memory associated with structure s is freed. This routine may be called any time after calling Rast_init_cell_stats().

Parameters
spointer to Cell_stats structure

Definition at line 385 of file cell_stats.c.

References Cell_stats::Cell_stats_node::count, G_free(), complex::i, Cell_stats::N, and Cell_stats::node.

void Rast_get_stats_for_null_value ( long *  count,
const struct Cell_stats s 
)

Get number of null values.

Get a number of null values from stats structure.

Note: when reporting values which appear in a map using Rast_next_cell_stats(), to get stats for null, call Rast_get_stats_for_null_value() first, since Rast_next_cell_stats() does not report stats for null.

Parameters
countcount
spointer to Cell_stats structure which holds cell stats info

Definition at line 372 of file cell_stats.c.

References Cell_stats::null_data_count.

void Rast_init_cell_stats ( struct Cell_stats s)

Initialize cell stats.

This routine, which must be called first, initializes the Cell_stats structure.

Set the count for NULL-values to zero.

Parameters
spointer to Cell_stats structure

Definition at line 39 of file cell_stats.c.

References INCR, Cell_stats::N, NODE, Cell_stats::node, Cell_stats::null_data_count, and Cell_stats::tlen.

int Rast_next_cell_stat ( CELL cat,
long *  count,
struct Cell_stats s 
)

Retrieve sorted cell stats.

Retrieves the next cat, count combination from the structure. Returns 0 if there are no more items, non-zero if there are more. For example:

struct Cell_stats s;
long count;
// updating <b>s</b> occurs here
while (Rast_next_cell_stat(&cat,&count,&s)
fprintf(stdout, "%ld %ld\n", (long) cat, count);

Do not return a record for the NULL-value

Parameters
catraster value
[out]count
spointer to Cell_stats structure which holds cell stats info
Returns
0 if there are no more items
non-zero if there are more

Definition at line 314 of file cell_stats.c.

References Cell_stats::Cell_stats_node::count, Cell_stats::curoffset, Cell_stats::curp, Cell_stats::Cell_stats_node::idx, Cell_stats::N, Cell_stats::node, and SHIFT.

Referenced by Rast_cell_stats_histo_eq(), Rast_histogram_eq_colors(), Rast_make_histogram_cs(), Rast_make_histogram_eq_colors(), Rast_make_histogram_log_colors(), and Rast_write_histogram_cs().

int Rast_rewind_cell_stats ( struct Cell_stats s)

Reset/rewind cell stats.

The structure s is rewound (i.e., positioned at the first raster category) so that sorted sequential retrieval can begin.

Parameters
spointer to Cell_stats structure which holds cell stats info
Returns
0

Definition at line 250 of file cell_stats.c.

References Cell_stats::curoffset, Cell_stats::curp, Cell_stats::Cell_stats_node::left, Cell_stats::N, and Cell_stats::node.

Referenced by Rast_cell_stats_histo_eq(), Rast_histogram_eq_colors(), Rast_make_histogram_cs(), Rast_make_histogram_eq_colors(), Rast_make_histogram_log_colors(), and Rast_write_histogram_cs().

int Rast_update_cell_stats ( const CELL cell,
int  n,
struct Cell_stats s 
)

Add data to cell stats.

The n CELL values in the data array are inserted (and counted) in the Cell_stats structure.

Look for NULLs and update the NULL-value count.

Parameters
cellraster values
nnumber of values
spointer to Cell_stats structure which holds cell stats info
Returns
1 on failure
0 on success

Definition at line 62 of file cell_stats.c.

References cat, INCR, Cell_stats::N, N, NODE, Cell_stats::node, Cell_stats::null_data_count, Rast_is_c_null_value(), SHIFT, and Cell_stats::tlen.