• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

quant_rw.c

Go to the documentation of this file.
00001 #include <grass/gis.h>
00002 #include <grass/glocale.h>
00003 #include <string.h>
00004 
00005 /*********************************************************************
00006 *
00007 *   G_quantize_fp_map(name, mapset, min, max)
00008 *   char *name, *mapset;   name of the map
00009 *   CELL min, max;         resulting int range
00010 *
00011 *   Writes necessary quant rules for map <name> so that
00012 *   a floating range of <name> is mapped into integer range (min, max)
00013 *
00014 **********************************************************************
00015 * 
00016 *   G_quantize_fp_map_range(name, mapset, d_min, d_max, min, max)
00017 *   char *name, *mapset;   name of the map
00018 *   CELL min, max;         resulting int range
00019 *   DCELL d_min, d_max;    floating point range
00020 *
00021 *   Make a rule for map <name> that maps floating range (d_min, d_max)
00022 *   into integer range (min, max)
00023 *   This function is useful when the quant rule doesn't depend of the
00024 *   range of produced float data, for example the slope map whould
00025 *   want to have a quant rule: 0.0, 90.0 -> 0 , 90
00026 *   no matter what the min and max slope of this map is.
00027 *
00028 **********************************************************************
00029 * 
00030 *   G_write_quant(name, mapset, quant)
00031 *        char *name, *mapset;
00032 *        struct Quant *quant;
00033 *   writes the quant rule table for the map <name>
00034 *
00035 **********************************************************************
00036 * 
00037 *   G_read_quant(name, mapset, quant)
00038 *        char *name, *mapset;
00039 *
00040 *   reads the quant table for name@mapset
00041 *
00042 **********************************************************************
00043 *
00044 *   G_truncate_fp_map(name, mapset)
00045 *        char *name, *mapset;
00046 *        struct Quant *quant;
00047 *
00048 *   writes the quant rules which indicate that all floating numbers
00049 *   should be truncated instead of applying any quant rules from
00050 *   floats to integers
00051 *
00052 **********************************************************************
00053 *
00054 *   G_round_fp_map(name, mapset)
00055 *        char *name, *mapset;
00056 *        struct Quant *quant;
00057 *
00058 *   writes the quant rules which indicate that all floating numbers
00059 *   should be rounded instead of applying any quant rules from
00060 *   floats to integers
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     /* quantize the map */
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     /* round the map */
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     /* quantize the map */
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     /* first actually write the rules */
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 }

Generated on Wed Oct 13 2010 12:09:30 for GRASS Programmer's Manual by  doxygen 1.7.1