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(char *name,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 {
00074 sprintf(buf, "G_truncate_fp_map: can't write quant rules for map %s", name); G_warning(buf);
00075 return -1;
00076 }
00077 return 1;
00078 }
00079
00080 int G_round_fp_map(char *name,char *mapset)
00081 {
00082 char buf[300];
00083 struct Quant quant;
00084
00085 G_quant_init(&quant);
00086 G_quant_round(&quant);
00087
00088 if(G_write_quant (name, mapset, &quant) < 0)
00089 {
00090 sprintf(buf, "G_truncate_fp_map: can't write quant rules for map %s", name); G_warning(buf);
00091 return -1;
00092 }
00093 return 1;
00094 }
00095
00096
00111 int G_quantize_fp_map(
00112 char *name,char *mapset,
00113 CELL min,CELL max)
00114 {
00115 char buf[300];
00116 DCELL d_min, d_max;
00117 struct FPRange fp_range;
00118
00119 if(G_read_fp_range(name, mapset, &fp_range) < 0)
00120 {
00121 sprintf(buf, "G_quantize_fp_map: can't read fp range for map %s", name);
00122 G_warning(buf);
00123 return -1;
00124 }
00125 G_get_fp_range_min_max(&fp_range, &d_min, &d_max);
00126 if(G_is_d_null_value(&d_min) || G_is_d_null_value(&d_max))
00127 {
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(
00160 char *name,char *mapset,
00161 DCELL d_min,DCELL d_max,
00162 CELL min,CELL max)
00163 {
00164 char buf[300];
00165 struct Quant quant;
00166
00167 G_quant_init(&quant);
00168 G_quant_add_rule(&quant, d_min, d_max, min, max);
00169
00170 if(G_write_quant (name, mapset, &quant) < 0)
00171 {
00172 sprintf(buf, "G_quantize_fp_map_range: can't write quant rules for map %s", name); G_warning(buf);
00173 return -1;
00174 }
00175 return 1;
00176 }
00177
00178
00179
00180
00181
00198 int G_write_quant(
00199 char *name,char *mapset,
00200 struct Quant *quant)
00201 {
00202 CELL cell_min, cell_max;
00203 DCELL d_min, d_max;
00204 char buf[300];
00205
00206 if (G_raster_map_type (name, mapset) == CELL_TYPE)
00207 {
00208 sprintf(buf, _("Cannot write quant rules: map %s is integer"), name);
00209 G_warning(buf);
00210 return -1;
00211 }
00212
00213 G_quant_get_limits (quant, &d_min, &d_max, &cell_min, &cell_max);
00214
00215
00216 if( G__quant_export (name, mapset, quant) < 0)
00217 {
00218 sprintf(buf, _("Cannot write quant rules for map %s"), name);
00219 G_warning(buf);
00220 return -1;
00221 }
00222
00223 return 1;
00224 }
00225
00226
00227
00228
00248 int G_read_quant(
00249 char *name,char *mapset,
00250 struct Quant *quant)
00251 {
00252 G_quant_init (quant);
00253 return G__quant_import(name, mapset, quant);
00254 }