00001 #include <grass/gis.h>
00002 #include <grass/glocale.h>
00003 #include <string.h>
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 int G_truncate_fp_map(const char *name, const char *mapset)
00065 {
00066 char buf[300];
00067 struct Quant quant;
00068
00069 G_quant_init(&quant);
00070 G_quant_truncate(&quant);
00071
00072 if (G_write_quant(name, mapset, &quant) < 0) {
00073 sprintf(buf, "G_truncate_fp_map: can't write quant rules for map %s",
00074 name);
00075 G_warning(buf);
00076 return -1;
00077 }
00078 return 1;
00079 }
00080
00081 int G_round_fp_map(const char *name, const char *mapset)
00082 {
00083 char buf[300];
00084 struct Quant quant;
00085
00086 G_quant_init(&quant);
00087 G_quant_round(&quant);
00088
00089 if (G_write_quant(name, mapset, &quant) < 0) {
00090 sprintf(buf, "G_truncate_fp_map: can't write quant rules for map %s",
00091 name);
00092 G_warning(buf);
00093 return -1;
00094 }
00095 return 1;
00096 }
00097
00098
00113 int G_quantize_fp_map(const char *name, const char *mapset,
00114 CELL min, CELL max)
00115 {
00116 char buf[300];
00117 DCELL d_min, d_max;
00118 struct FPRange fp_range;
00119
00120 if (G_read_fp_range(name, mapset, &fp_range) < 0) {
00121 sprintf(buf, "G_quantize_fp_map: can't read fp range for map %s",
00122 name);
00123 G_warning(buf);
00124 return -1;
00125 }
00126 G_get_fp_range_min_max(&fp_range, &d_min, &d_max);
00127 if (G_is_d_null_value(&d_min) || G_is_d_null_value(&d_max)) {
00128 sprintf(buf, "G_quantize_fp_map: raster map %s is empty", name);
00129 G_warning(buf);
00130 return -1;
00131 }
00132 return G_quantize_fp_map_range(name, mapset, d_min, d_max, min, max);
00133 }
00134
00135
00136
00137
00159 int G_quantize_fp_map_range(const char *name, const char *mapset,
00160 DCELL d_min, DCELL d_max, CELL min, CELL max)
00161 {
00162 char buf[300];
00163 struct Quant quant;
00164
00165 G_quant_init(&quant);
00166 G_quant_add_rule(&quant, d_min, d_max, min, max);
00167
00168 if (G_write_quant(name, mapset, &quant) < 0) {
00169 sprintf(buf,
00170 "G_quantize_fp_map_range: can't write quant rules for map %s",
00171 name);
00172 G_warning(buf);
00173 return -1;
00174 }
00175 return 1;
00176 }
00177
00178
00179
00180
00181
00198 int G_write_quant(const char *name, const char *mapset,
00199 const struct Quant *quant)
00200 {
00201 CELL cell_min, cell_max;
00202 DCELL d_min, d_max;
00203 char buf[300];
00204
00205 if (G_raster_map_type(name, mapset) == CELL_TYPE) {
00206 sprintf(buf, _("Cannot write quant rules: map %s is integer"), name);
00207 G_warning(buf);
00208 return -1;
00209 }
00210
00211 G_quant_get_limits(quant, &d_min, &d_max, &cell_min, &cell_max);
00212
00213
00214 if (G__quant_export(name, mapset, quant) < 0) {
00215 sprintf(buf, _("Cannot write quant rules for map %s"), name);
00216 G_warning(buf);
00217 return -1;
00218 }
00219
00220 return 1;
00221 }
00222
00223
00224
00225
00245 int G_read_quant(const char *name, const char *mapset, struct Quant *quant)
00246 {
00247 G_quant_init(quant);
00248 return G__quant_import(name, mapset, quant);
00249 }