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(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     /* quantize the map */
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     /* round the map */
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     /* quantize the map */
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      /* first actually write the rules */
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 }

Generated on Wed Dec 19 14:59:06 2007 for GRASS by  doxygen 1.5.4