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

Go to the source code of this file.

Macros

#define SIG   struct One_Sig
 

Functions

int I_init_signatures (struct Signature *S, int nbands)
 Initialize struct Signature before use. More...
 
int I_new_signature (struct Signature *S)
 
int I_free_signatures (struct Signature *S)
 Free memory allocated for struct Signature. More...
 
int I_read_one_signature (FILE *fd, struct Signature *S)
 
int I_read_signatures (FILE *fd, struct Signature *S)
 Read signatures from file. More...
 
int I_write_signatures (FILE *fd, struct Signature *S)
 Write signatures to file. More...
 
char ** I_sort_signatures_by_semantic_label (struct Signature *S, const struct Ref *R)
 Reorder struct Signature to match imagery group member order. More...
 

Macro Definition Documentation

◆ SIG

#define SIG   struct One_Sig

Definition at line 27 of file sig.c.

Referenced by I_new_signature().

Function Documentation

◆ I_free_signatures()

int I_free_signatures ( struct Signature S)

Free memory allocated for struct Signature.

One must call I_init_signatures() to re-use struct after it has been passed to this function.

Parameters
*Signatureto free
Returns
always 0

Definition at line 59 of file sig.c.

References free(), One_Sig::mean, Signature::nbands, Signature::nsigs, NULL, Signature::semantic_labels, Signature::sig, Signature::title, and One_Sig::var.

Referenced by I_cluster_begin().

◆ I_init_signatures()

int I_init_signatures ( struct Signature S,
int  nbands 
)

Initialize struct Signature before use.

No need to call before calling I_read_signatures.

Parameters
*Signatureto initialize
nbandsband (imagery group member) count

Definition at line 14 of file sig.c.

References G_malloc, Signature::nbands, Signature::nsigs, NULL, Signature::semantic_labels, Signature::sig, and Signature::title.

Referenced by I_cluster_begin(), I_cluster_clear(), and I_iclass_init_signatures().

◆ I_new_signature()

int I_new_signature ( struct Signature S)

◆ I_read_one_signature()

int I_read_one_signature ( FILE *  fd,
struct Signature S 
)

Definition at line 84 of file sig.c.

◆ I_read_signatures()

int I_read_signatures ( FILE *  fd,
struct Signature S 
)

Read signatures from file.

File stream should be opened in advance by call to I_fopen_signature_file_old() It is up to caller to fclose the file stream afterwards.

There is no need to initialize struct Signature in advance, as this function internally calls I_init_signatures.

Parameters
pointerto FILE*
pointerto struct Signature *S
Returns
1 on success, -1 on failure

Definition at line 141 of file sig.c.

◆ I_sort_signatures_by_semantic_label()

char** I_sort_signatures_by_semantic_label ( struct Signature S,
const struct Ref R 
)

Reorder struct Signature to match imagery group member order.

The function will check for semantic label match between signature struct and imagery group.

In the case of a complete semantic label match, values of passed in struct Signature are reordered to match the order of imagery group items.

If all semantic labels are not identical (in arbitrary order), function will return two dimensional array with comma separated list of:

  • [0] semantic labels present in the signature struct but absent in the imagery group
  • [1] semantic labels present in the imagery group but absent in the signature struct

If no mismatch of simantic labels for signatures or imagery group are detected (== all are present in the other list), a NULL value will be returned in the particular list of mismatches (not an empty string). For example:

if (ret && ret[1]) printf("List of imagery group bands without signatures: %s\n, ret[1]);
Parameters
*Signatureexisting signatures to check & sort
*Refgroup reference
Returns
NULL successfully sorted
err_array two comma separated lists of mismatches

Definition at line 300 of file sig.c.

References Ref::file, G_calloc, G_fatal_error(), G_malloc, Ref_Files::mapset, Ref_Files::name, Signature::nbands, Ref::nfiles, Signature::nsigs, and Rast_get_semantic_label_or_name().

◆ I_write_signatures()

int I_write_signatures ( FILE *  fd,
struct Signature S 
)

Write signatures to file.

File stream should be opened in advance by call to I_fopen_signature_file_new() It is up to caller to fclose the file stream afterwards.

Parameters
pointerto FILE*
pointerto struct Signature *S
Returns
always 1

Definition at line 228 of file sig.c.