GRASS 8 Programmer's Manual 8.6.0dev(2026)-1878fdfec5
Loading...
Searching...
No Matches
iclass.c
Go to the documentation of this file.
1/*!
2 \file lib/imagery/iclass.c
3
4 \brief Imagery library - functions for wx.iclass
5
6 Computation based on training areas for supervised classification.
7 Based on i.class module (GRASS 6).
8
9 SPDX-FileCopyrightText: 1999-2007, 2011 GRASS Development Team
10 SPDX-License-Identifier: GPL-2.0-or-later
11
12 \author David Satnik, Central Washington University (original author)
13 \author Markus Neteler <neteler itc.it> (i.class module)
14 \author Bernhard Reiter <bernhard intevation.de> (i.class module)
15 \author Brad Douglas <rez touchofmadness.com>(i.class module)
16 \author Glynn Clements <glynn gclements.plus.com> (i.class module)
17 \author Hamish Bowman <hamish_b yahoo.com> (i.class module)
18 \author Jan-Oliver Wagner <jan intevation.de> (i.class module)
19 \author Anna Kratochvilova <kratochanna gmail.com> (rewriting for wx.iclass)
20 \author Vaclav Petras <wenzeslaus gmail.com> (rewriting for wx.iclass)
21 */
22
23#include <grass/imagery.h>
24#include <grass/glocale.h>
25#include <grass/vector.h>
26
27#include "iclass_local_proto.h"
28
29/*!
30 \brief Calculates statistical values for one class and multiple bands based
31 on training areas.
32
33 Calculates values statistical based on the cells
34 that are within training areas. Creates raster map
35 to display the cells of the image bands which fall
36 within standard deviations from the means.
37
38 \param statistics pointer to bands statistics
39 \param refer pointer to band files structure
40 \param map_info vector map with training areas
41 \param layer_name vector layer
42 \param group name of imagery group
43 \param raster_name name of temporary raster map (to be created)
44
45 \return number of processed training areas
46 \return -1 on failure
47 */
49 struct Map_info *map_info, const char *layer_name,
50 const char *group, const char *raster_name)
51{
52 int ret;
53
54 int category;
55
57
59
60 int *band_fd;
61
63
64 G_debug(1, "iclass_analysis(): group = %s", group);
65
66 category = statistics->cat;
67
68 /* region set to current working region */
70
71 /* find perimeter points from vector map */
74 if (ret < 0) {
75 return -1;
76 }
77 else if (ret == 0) {
78 G_warning(_("No areas in category %d"), category);
79 return 0;
80 }
81
87
89 return ret;
90}
91
92/*!
93 \brief Read files for the specified group subgroup into the Ref structure.
94
95 \param group_name name of imagery group
96 \param subgroup_name name of imagery subgroup
97 \param subgroup_name if it is NULL, bands from group will be used
98 \param[out] refer pointer to band files structure
99
100 \return 1 on success
101 \return 0 on failure
102 */
103int I_iclass_init_group(const char *group_name, const char *subgroup_name,
104 struct Ref *refer)
105{
106 int n;
107
108 G_debug(3, "I_iclass_init_group(): group_name = %s, subgroup_name = %s",
110 I_init_group_ref(refer); /* called in I_get_group_ref */
111
112 if (subgroup_name)
114 else
116
117 for (n = 0; n < refer->nfiles; n++) {
118 if (G_find_raster(refer->file[n].name, refer->file[n].mapset) == NULL) {
119 if (subgroup_name)
120 G_warning(_("Raster map <%s@%s> in subgroup "
121 "<%s> does not exist"),
122 refer->file[n].name, refer->file[n].mapset,
124 else
125 G_warning(_("Raster map <%s@%s> in group "
126 "<%s> does not exist"),
127 refer->file[n].name, refer->file[n].mapset,
128 group_name);
129
131 return 0;
132 }
133 }
134
135 if (refer->nfiles <= 1) {
136 if (subgroup_name)
137 G_warning(
138 _("Subgroup <%s> does not have enough files (it has %d files)"),
139 subgroup_name, refer->nfiles);
140 else
141 G_warning(
142 _("Group <%s> does not have enough files (it has %d files)"),
143 group_name, refer->nfiles);
145 return 0;
146 }
147
148 return 1;
149}
150
151/*!
152 \brief Create raster map based on statistics.
153
154 \param statistics pointer to bands statistics
155 \param refer pointer to band files structure
156 \param raster_name name of temporary raster map (to be created)
157 */
159 const char *raster_name)
160{
162
163 int *band_fd;
164
165 int b;
166
167 for (b = 0; b < statistics->nbands; b++) {
169 }
170
174}
#define NULL
Definition ccmath.h:32
AMI_err name(char **stream_name)
Definition ami_stream.h:426
const char * G_find_raster(char *, const char *)
Find a raster map.
Definition find_rast.c:52
void G_warning(const char *,...) __attribute__((format(printf
void G_get_set_window(struct Cell_head *)
Get the current working window (region)
int G_debug(int, const char *,...) __attribute__((format(printf
int I_init_group_ref(struct Ref *)
initialize Ref structure
Definition group.c:455
int I_get_group_ref(const char *, struct Ref *)
read group REF file
Definition group.c:108
int I_free_group_ref(struct Ref *)
free Ref structure
Definition group.c:472
int I_get_subgroup_ref(const char *, const char *, struct Ref *)
read subgroup REF file
Definition group.c:143
int CELL
Definition gis.h:631
#define _(str)
Definition glocale.h:10
void I_iclass_create_raster(IClass_statistics *statistics, struct Ref *refer, const char *raster_name)
Create raster map based on statistics.
Definition iclass.c:158
int I_iclass_init_group(const char *group_name, const char *subgroup_name, struct Ref *refer)
Read files for the specified group subgroup into the Ref structure.
Definition iclass.c:103
int I_iclass_analysis(IClass_statistics *statistics, struct Ref *refer, struct Map_info *map_info, const char *layer_name, const char *group, const char *raster_name)
Calculates statistical values for one class and multiple bands based on training areas.
Definition iclass.c:48
void close_band_files(struct Ref *refer, CELL **band_buffer, int *band_fd)
Close and free space for the group band files.
void open_band_files(struct Ref *refer, CELL ***band_buffer, int **band_fd)
Open and allocate space for the group band files.
int vector2perimeters(struct Map_info *Map, const char *layer_name, int category, IClass_perimeter_list *perimeters, struct Cell_head *band_region)
Creates perimeters from vector areas of given category.
void free_perimeters(IClass_perimeter_list *perimeters)
Frees all perimeters in list of perimeters.
void alloc_statistics(IClass_statistics *statistics, int nbands)
Allocate space for statistics.
void band_range(IClass_statistics *statistics, int band)
Helper function for computing min and max range in one band.
void create_raster(IClass_statistics *statistics, CELL **band_buffer, int *band_fd, const char *raster_name)
Create raster map based on statistics.
int make_all_statistics(IClass_statistics *statistics, IClass_perimeter_list *perimeters, CELL **band_buffer, int *band_fd)
Calculate statistics for all training areas.
double b
Definition r_raster.c:37
2D/3D raster map header (used also for region)
Definition gis.h:443
Vector map info.
Definition imagery.h:24