GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
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

◆ INCR

#define INCR   10

Definition at line 19 of file cell_stats.c.

◆ NODE

#define NODE   struct Cell_stats_node

Definition at line 24 of file cell_stats.c.

◆ SHIFT

#define SHIFT   6

Definition at line 20 of file cell_stats.c.

Function Documentation

◆ Rast_find_cell_stat()

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.

◆ Rast_free_cell_stats()

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.

◆ Rast_get_stats_for_null_value()

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.

◆ Rast_init_cell_stats()

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.

◆ Rast_next_cell_stat()

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;
CELL cat;
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::curoffset, and Cell_stats::N.

Referenced by Rast_make_histogram_cs().

◆ Rast_rewind_cell_stats()

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.

Referenced by Rast_make_histogram_cs().

◆ Rast_update_cell_stats()

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.