raster.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. #ifndef GRASS_RASTER_H
  2. #define GRASS_RASTER_H
  3. #include <grass/gis.h>
  4. /*** defines ***/
  5. #define RECLASS_TABLE 1
  6. #define RECLASS_RULES 2
  7. #define RECLASS_SCALE 3
  8. #define CELL_TYPE 0
  9. #define FCELL_TYPE 1
  10. #define DCELL_TYPE 2
  11. /*! \brief Interpolation methods
  12. For G_get_raster_sample(), INTERP_TYPE
  13. */
  14. #define INTERP_UNKNOWN 0
  15. #define INTERP_NEAREST 1 /* nearest neighbor interpolation */
  16. #define INTERP_BILINEAR 2 /* bilinear interpolation */
  17. #define INTERP_BICUBIC 3 /* bicubic interpolation */
  18. /*** typedefs ***/
  19. typedef int RASTER_MAP_TYPE;
  20. /* for G_get_raster_sample() */
  21. typedef int INTERP_TYPE;
  22. /*** structures ***/
  23. struct Reclass
  24. {
  25. char *name; /* name of raster map being reclassed */
  26. char *mapset; /* mapset in which "name" is found */
  27. int type; /* type of reclass */
  28. int num; /* size of reclass table */
  29. CELL min; /* table min */
  30. CELL max; /* table max */
  31. CELL *table; /* reclass table */
  32. };
  33. struct FPReclass_table
  34. {
  35. DCELL dLow; /* domain low */
  36. DCELL dHigh; /* domain high */
  37. DCELL rLow; /* range low */
  38. DCELL rHigh; /* range high */
  39. };
  40. /* reclass structure from double to double used by r.recode to reclass */
  41. /* between types: int to double, float to int,... */
  42. struct FPReclass
  43. {
  44. int defaultDRuleSet; /* 1 if default domain rule set */
  45. int defaultRRuleSet; /* 1 if default range rule set */
  46. int infiniteLeftSet; /* 1 if negative infinite interval rule exists */
  47. int infiniteRightSet; /* 1 if positive infinite interval rule exists */
  48. int rRangeSet; /* 1 if range range (i.e. interval) is set */
  49. int maxNofRules;
  50. int nofRules;
  51. DCELL defaultDMin; /* default domain minimum value */
  52. DCELL defaultDMax; /* default domain maximum value */
  53. DCELL defaultRMin; /* default range minimum value */
  54. DCELL defaultRMax; /* default range maximum value */
  55. DCELL infiniteDLeft; /* neg infinite rule */
  56. DCELL infiniteDRight; /* neg infinite rule */
  57. DCELL infiniteRLeft; /* pos infinite rule */
  58. DCELL infiniteRRight; /* pos infinite rule */
  59. DCELL dMin; /* minimum domain values in rules */
  60. DCELL dMax; /* maximum domain values in rules */
  61. DCELL rMin; /* minimum range values in rules */
  62. DCELL rMax; /* maximum range values in rules */
  63. struct FPReclass_table *table;
  64. };
  65. struct Quant_table
  66. {
  67. DCELL dLow;
  68. DCELL dHigh;
  69. CELL cLow;
  70. CELL cHigh;
  71. };
  72. struct Quant
  73. {
  74. int truncate_only;
  75. int round_only;
  76. int defaultDRuleSet;
  77. int defaultCRuleSet;
  78. int infiniteLeftSet;
  79. int infiniteRightSet;
  80. int cRangeSet;
  81. int maxNofRules;
  82. int nofRules;
  83. DCELL defaultDMin;
  84. DCELL defaultDMax;
  85. CELL defaultCMin;
  86. CELL defaultCMax;
  87. DCELL infiniteDLeft;
  88. DCELL infiniteDRight;
  89. CELL infiniteCLeft;
  90. CELL infiniteCRight;
  91. DCELL dMin;
  92. DCELL dMax;
  93. CELL cMin;
  94. CELL cMax;
  95. struct Quant_table *table;
  96. struct
  97. {
  98. DCELL *vals;
  99. /* pointers to quant rules corresponding to the intervals btwn vals */
  100. struct Quant_table **rules;
  101. int nalloc;
  102. int active;
  103. DCELL inf_dmin;
  104. DCELL inf_dmax;
  105. CELL inf_min;
  106. CELL inf_max;
  107. /* all values smaller than inf_dmin become inf_min */
  108. /* all values larger than inf_dmax become inf_max */
  109. /* inf_min and/or inf_max can be NULL if there are no inf rules */
  110. } fp_lookup;
  111. };
  112. struct Categories
  113. {
  114. CELL ncats; /* total number of categories */
  115. CELL num; /* the highest cell values. Only exists
  116. for backwards compatibility = (CELL)
  117. max_fp_values in quant rules */
  118. char *title; /* name of data layer */
  119. char *fmt; /* printf-like format to generate labels */
  120. float m1; /* Multiplication coefficient 1 */
  121. float a1; /* Addition coefficient 1 */
  122. float m2; /* Multiplication coefficient 2 */
  123. float a2; /* Addition coefficient 2 */
  124. struct Quant q; /* rules mapping cell values to index in
  125. list of labels */
  126. char **labels; /* array of labels of size num */
  127. int *marks; /* was the value with this label was used? */
  128. int nalloc;
  129. int last_marked_rule;
  130. /* NOTE: to get a rule corresponfing to cats.labels[i], use */
  131. /* G_get_ith_c/f/d_raster_cat (pcats, i, val1, val2) */
  132. /* it calls */
  133. /* G_quant_get_ith_rule(&cats->q, i, val1, val2, &index, &index); */
  134. /* and idex ==i, because rule is added at the same time as a */
  135. /* label, and quant rules are never reordered. Olga apr,95 */
  136. };
  137. /*! \brief Raster history info (metadata)
  138. See History structure for implementation issues.
  139. */
  140. enum History_field
  141. {
  142. /*! \brief Raster name */
  143. HIST_MAPID,
  144. /*! \brief Raster title */
  145. HIST_TITLE,
  146. /*! \brief Raster mapset */
  147. HIST_MAPSET,
  148. /*! \brief User who creater raster map */
  149. HIST_CREATOR,
  150. /*! \brief Map type ("raster", "reclass", "GDAL-link", or "virtual") */
  151. HIST_MAPTYPE,
  152. /*! \brief Description of original data source (two lines) */
  153. HIST_DATSRC_1,
  154. HIST_DATSRC_2,
  155. /*! \brief One-line data description */
  156. HIST_KEYWRD,
  157. /*! \brief Number of fields to be defined in History structure */
  158. HIST_NUM_FIELDS
  159. };
  160. /*! \brief Raster history info (metadata) */
  161. struct History
  162. {
  163. /*! \brief Array of fields (see \ref History_field for details) */
  164. char *fields[HIST_NUM_FIELDS];
  165. /*! \brief Number of lines in lines array */
  166. int nlines;
  167. /*! \brief Lines array */
  168. char **lines;
  169. };
  170. struct Cell_stats
  171. {
  172. struct Cell_stats_node
  173. {
  174. int idx;
  175. long *count;
  176. int left;
  177. int right;
  178. } *node; /* tree of values */
  179. int tlen; /* allocated tree size */
  180. int N; /* number of actual nodes in tree */
  181. int curp;
  182. long null_data_count;
  183. int curoffset;
  184. };
  185. struct Histogram
  186. {
  187. int num;
  188. struct Histogram_list
  189. {
  190. CELL cat;
  191. long count;
  192. } *list;
  193. };
  194. struct R_stats
  195. {
  196. DCELL sum;
  197. DCELL sumsq;
  198. grass_int64 count;
  199. };
  200. struct Range
  201. {
  202. CELL min;
  203. CELL max;
  204. int first_time; /* whether or not range was updated */
  205. struct R_stats rstats;
  206. };
  207. struct FPRange
  208. {
  209. DCELL min;
  210. DCELL max;
  211. int first_time; /* whether or not range was updated */
  212. struct R_stats rstats;
  213. };
  214. struct FP_stats {
  215. int geometric;
  216. int geom_abs;
  217. int flip;
  218. int count;
  219. DCELL min, max;
  220. unsigned long *stats;
  221. unsigned long total;
  222. };
  223. struct GDAL_link;
  224. struct R_vrt;
  225. /*** prototypes ***/
  226. #include <grass/defs/raster.h>
  227. #endif /* GRASS_RASTER_H */