rasterlib.dox 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230
  1. /*! \page rasterlib GRASS Raster Library
  2. <!-- * doxygenized from "GRASS 5 Programmer's Manual"
  3. by M. Neteler 2/2004, 8/2005, 2006
  4. * updated to GRASS 7 by Martin Landa
  5. -->
  6. by GRASS Development Team (http://grass.osgeo.org)
  7. \tableofcontents
  8. <b>TODO: Needs to be cleaned up. The upper GRASS 4.x and the lower
  9. GRASS 5.x/6.x parts need to me merged and updated to GRASS 7</b>
  10. \section gisrastintro GRASS Raster Map Processing
  11. This library provides a suite of routines which process raster map file.
  12. The processing of raster map files consists of determining which
  13. raster map file or files are to be processed (specified on the module
  14. command line), locating the raster map file in the database, opening the
  15. raster files, dynamically allocating i/o buffers, reading or writing
  16. the raster files, closing the raster files, and creating support files
  17. for newly created raster maps.
  18. Raster map data can be of type CELL, FCELL or DCELL, they are defined
  19. in "gis.h". CELL is a 32-bit signed integer, FCELL is an IEEE
  20. single-precision floating-point, and DCELL is an IEEE double-precision
  21. floating-point. 3D rasters (grid3d) is treated as DCELL (see related
  22. library).
  23. \section Finding_Raster_Files_in_the_Database Finding Raster Files in the Database
  24. GRASS allows the user to specify raster map names (or any other
  25. GIS database file) either as a simple <em>unqualified</em> name, such as
  26. "soils", or in case of input raster maps also as a <em>fully qualified</em>
  27. name, such as "soils@mapset", where <i>mapset</i> is the mapset where the raster
  28. map is to be found. Often only the unqualified raster map name is
  29. provided on the command line and searched in all mapsets indicated in
  30. the mapset search path (SEARCH_PATH file in the actual mapset; managed
  31. with <tt>g.mapsets</tt> command).
  32. The following routines search the database for raster map files:
  33. - G_find_raster()
  34. Looks for the raster file in the database. If found, the mapset where
  35. the raster file lives is returned. If not found, the NULL pointer is
  36. returned. If the user specifies a fully qualified raster map name which
  37. exists, then G_find_raster() modifies <i>name</i> by removing
  38. the "@<I>mapset</I>".
  39. For example, to find a raster map in all mapsets listed the mapset search
  40. path:
  41. \code
  42. char name[GNAME_MAX];
  43. char *mapset;
  44. if ((mapset = G_find_raster(name,"")) == NULL)
  45. /* not found */
  46. \endcode
  47. To check that the raster map exists in the current mapset:
  48. \code
  49. char name[GNAME_MAX];
  50. if (G_find_raster(name, G_mapset()) == NULL)
  51. /* not found */
  52. \endcode
  53. \section Opening_an_Existing_Raster_File Opening an Existing Raster File
  54. The following routine opens the raster map file for <em>reading</em>.
  55. - Rast_open_old()
  56. This routine opens the raster map in given mapset for reading. A
  57. nonnegative file descriptor is returned if the open is
  58. successful. Otherwise a diagnostic message is printed and a negative
  59. value is returned. This routine does quite a bit of work. Since GRASS
  60. users expect that all raster maps will be resampled into the current
  61. region (nearest neighbor method), the resampling index for the raster
  62. map is prepared by this routine after the map is opened. The resampling
  63. is based on the active module region. Preparation required for reading
  64. the various raster map formats (CELL, FCELL, DCELL) is also done.
  65. \section Creating_and_Opening_New_Raster_Files Creating and Opening New Raster Files
  66. The following routines create a new raster map in the current
  67. mapset and open it for <em>writing</em>. G_legal_filename() should be
  68. called first to make sure that raster map name is a valid name.
  69. <b>Note:</b> It is not an error for raster map to already exist. New
  70. raster maps are actually created as temporary files and moved into
  71. the cell or fcell directory when closed. This allows an existing raster map
  72. to be read at the same time that it is being rewritten. G_find_raster()
  73. could be used to see if raster map already exists.
  74. <b>Warning:</b> However, there is a subtle trap. The temporary file,
  75. which is created using G_tempfile(), is named using the current
  76. process id. If the new raster file is opened by a parent process which
  77. exits after creating a child process using fork(), the raster file may
  78. never get created since the temporary file would be associated with
  79. the parent process, not the child. GRASS management automatically
  80. removes temporary files associated with processes that are no longer
  81. running. If fork() must be used, the safest course of action is to
  82. create the child first, then open the raster file (see the discussion
  83. under G_tempfile() for more details).
  84. - Rast_open_new()
  85. - Rast_open_c_new()
  86. - Rast_open_fp_new()
  87. Creates and opens the raster map for writing by Rast_put_row() which
  88. writes the file row by row in <b>sequential</b> order. The raster file data
  89. will be compressed as it is written. A nonnegative file descriptor is
  90. returned if the open is successful. Otherwise a diagnostic message is
  91. printed and a negative value is returned.
  92. - Rast_open_new_uncompressed()
  93. - Rast_open_c_new_uncompressed()
  94. - Rast_open_fp_new_uncompressed()
  95. Creates and opens the raster file for writing by Rast_put_row() which
  96. writes the file row by row in sequential order. The raster file will
  97. be in uncompressed format when closed. A nonnegative file descriptor
  98. is returned if the open is successful. Otherwise a warning message is
  99. printed on stderr and a negative value is returned.
  100. General use of this routine is not recommended. This routine is
  101. provided so the <tt>r.compress</tt> module can create uncompressed
  102. raster files.
  103. \section Allocating_Raster_I_O_Buffers Allocating Raster I/O Buffers
  104. Since there is no predefined limit for the number of columns in the
  105. region, buffers which are used for reading and writing raster data
  106. must be dynamically allocated.
  107. - Rast_allocate_buf()
  108. - Rast_allocate_c_buf()
  109. - Rast_allocate_f_buf()
  110. - Rast_allocate_d_buf()
  111. This routine allocates a buffer of type CELL/FCELL/DCELL just large enough
  112. to hold one row of raster data (based on the number of columns in the active
  113. region).
  114. \code
  115. int input_fd;
  116. char inmap;
  117. RASTER_MAP_TYPE data_type;
  118. input_fd = Rast_open_old(inmap, "");
  119. data_type = Rast_get_map_type(input_fd);
  120. cell = Rast_allocate_buf(data_type);
  121. \endcode
  122. <i>FIXME 7/2009: next still true?</i>
  123. If larger buffers are required, the routine G_malloc() can be
  124. used.
  125. If sufficient memory is not available, an error message is printed and
  126. exit() is called.
  127. - G_zero_buf()
  128. This routines assigns each member of the raster buffer array to zero.
  129. It assumes that the buffer has been allocated using
  130. Rast_allocate_c_buf().
  131. \section Reading_Raster_Files Reading Raster Files
  132. Raster data can be thought of as a two-dimensional matrix. The
  133. routines described below read one full row of the matrix. It should be
  134. understood, however, that the number of rows and columns in the matrix
  135. is determined by the region, not the raster file itself. Raster data
  136. is always read resampled (nearest neighbor) into the region. This allows
  137. the user to specify the coverage of the database during analyses. It also
  138. allows databases to consist of raster files which do not cover exactly the
  139. same area, or do not have the same grid cell resolution. When raster
  140. files are resampled into the region, they all "look" the same.
  141. <b>Note:</b> The rows and columns are specified "C style", i.e.,
  142. starting with 0.
  143. - Rast_get_row()
  144. This routine reads the specified <i>row</i> from the raster file open
  145. on file descriptor (as returned by Rast_open_old()) into the
  146. buffer. The buffer must be dynamically allocated large enough to hold
  147. one full row of raster data. It can be allocated using
  148. Rast_allocate_buf(). This routine prints a diagnostic message and
  149. returns -1 if there is an error reading the raster file. Otherwise a
  150. nonnegative value is returned.
  151. - Rast_get_row_nomask()
  152. This routine reads the specified row from the raster file open on file
  153. descriptor into the buffer like Rast_get_row() does. The difference
  154. is that masking is suppressed. If the user has a mask set,
  155. Rast_get_row() will apply the mask but Rast_get_row_nomask() will
  156. ignore it. This routine prints a diagnostic message and returns -1 if
  157. there is an error reading the raster file. Otherwise a nonnegative
  158. value is returned.
  159. <b>Note:</b> Ignoring the mask is not generally acceptable. Users
  160. expect the mask to be applied. However, in some cases ignoring the
  161. mask is justified. For example, the GRASS modules <tt>r.describe</tt>,
  162. which reads the raster file directly to report all data values in a
  163. raster file, and <tt>r.slope.aspect</tt>, which produces slope and
  164. aspect from elevation, ignore both the mask and the region. However,
  165. the number of GRASS modules which do this should be minimal. See \ref
  166. Mask for more information about the mask.
  167. \subsection Writing_Raster_Files Writing Raster Files
  168. - Rast_put_row()
  169. This routine writes one row of raster data from buffer to the raster
  170. file open on file descriptor. The raster file must have been opened
  171. with Rast_open_new(). The buffer must have been allocated large
  172. enough for the region, perhaps using Rast_allocate_buf(). If there
  173. is an error writing the raster file, a warning message is printed and
  174. -1 is returned. Otherwise 1 is returned.
  175. <b>Note:</b> The rows are written in <b>sequential</b> order. The
  176. first call writes row 0, the second writes row 1, etc. The following
  177. example assumes that the raster file is to be created:
  178. \code
  179. int fd, row, nrows, ncols;
  180. CELL *buf;
  181. RASTER_MAP_TYPE data_type;
  182. fd = Rast_open_old(inmap, ""); /*...data for the row */
  183. data_type = Rast_get_map_type(fd);
  184. Rast_put_row(fd, buf, data_type);
  185. \endcode
  186. \subsection Closing_Raster_Files Closing Raster Files
  187. All raster files are closed by one of the following routines, whether
  188. opened for reading or for writing.
  189. - Rast_close()
  190. The raster file opened on file descriptor is closed. Memory allocated
  191. for raster processing is freed. If open for writing, skeletal support
  192. files for the new raster file are created as well.
  193. <b>Note:</b> If a module wants to explicitly write support files
  194. (e.g., a specific color table) for a raster file it creates, it must
  195. do so after the raster file is closed. Otherwise the close will
  196. overwrite the support files. See \ref Raster_Map_Layer_Support_Routines
  197. for routines which write raster support files.
  198. - Rast_unopen()
  199. The raster file opened on file descriptor is closed. Memory allocated
  200. for raster processing is freed. If open for writing, the raster file
  201. is not created and the temporary file created when the raster file was
  202. opened is removed (see \ref Creating_and_Opening_New_Raster_Files).
  203. This routine is useful when errors are detected and it is desired to
  204. not create the new raster file. While it is true that the raster file
  205. will not be created if the module exits without closing the file, the
  206. temporary file will not be removed at module exit. GRASS database
  207. management will eventually remove the temporary file, but the file can
  208. be quite large and will take up disk space until GRASS does remove
  209. it. Use this routine as a courtesy to the user.
  210. \section Raster_Map_Layer_Support_Routines Raster Map Layer Support Routines
  211. GRASS map layers have a number of support files associated with
  212. them. These files are discussed in detail in \ref Raster_Maps. The
  213. support files are the <em>raster header</em>, the <em>category</em>
  214. file, the <em>color</em> table, the <em>history</em> file, and the
  215. <em>range</em> file. Each support file has its own data structure and
  216. associated routines.
  217. \section Raster_Header_File Raster Header File
  218. The raster header file (<tt>cellhd</tt>) contains information
  219. describing the geographic extent of the raster map, the grid cell
  220. resolution, the format used to store the data in the raster file, see
  221. Cell_head structure for details. The routines described below use the
  222. Cell_head structure which is shown in detail in \ref
  223. GIS_Library_Data_Structures.
  224. - Rast_get_cellhd()
  225. The raster header for the raster file in the specified mapset is read
  226. into the Cell_head structure.
  227. <b>Note:</b> If the raster file is a reclassified, the raster header
  228. for the referenced raster file is read instead. See Rast_is_reclass()
  229. for distinguishing reclass files from regular raster files.
  230. <b>Note:</b> It is not necessary to get the raster header for a map
  231. layer in order to read the raster file data. The routines which read
  232. raster file data automatically retrieve the raster header information
  233. and use it for resampling the raster file data into the active
  234. region. If it is necessary to read the raster file directly without
  235. resampling into the active region, then the raster header can be used
  236. to set the active region using G_set_window().
  237. - G_adjust_Cell_head()
  238. This function fills in missing parts of the input cell header (or
  239. region). It also makes projection-specific adjustments.
  240. - Rast_put_cellhd()
  241. This routine writes the information from the Cell_head structure to
  242. the raster header file for the map layer in the current mapset.
  243. <b>Note:</b> Programmers should have no reason to use this routine. It
  244. is used by Rast_close() to give new raster files correct header
  245. files, and by the <tt>r.support</tt> module to give users a means of
  246. creating or modifying raster headers.
  247. - Rast_is_reclass()
  248. This function determines if the raster file is a reclass file. Returns
  249. 1 if raster file is a reclass file, 0 if it is not, and -1 if there
  250. was a problem reading the raster header.
  251. - Rast_is_reclassed_to()
  252. This function generates a child reclass maps list from the
  253. cell_misc/reclassed_to file which stores this list. The
  254. cell_misc/reclassed_to file is written by
  255. Rast_put_reclass(). Rast_is_reclassed_to() is used by <tt>g.rename</tt>,
  256. <tt>g.remove</tt> and <tt>r.reclass</tt> to prevent accidentally
  257. deleting the parent map of a reclassed raster map.
  258. \section Raster_split_windows Raster split windows
  259. The input window determines the number of rows and columns for
  260. Rast_get_row() etc, i.e. the valid range for the "row" parameter, and the
  261. number of elements in the "buf" array.
  262. The output window determines the number of rows and columns for
  263. Rast_put_row() etc, i.e. the number of times it should be called ("put"
  264. operations don't have a "row" parameter) and the number of elements in the
  265. "buf" array.
  266. For most modules, the input and output windows should be the same, but
  267. e.g. <tt>r.resamp.*</tt> will typically use split windows.
  268. The rationale was that the old GRASS 6 mechanism was inefficient. It would change
  269. the window twice for each row of output (set "read" window, read rows, set
  270. "write" window, write row). Each change caused the column mapping to be
  271. recalculated for each input map. With split windows, there are separate
  272. windows for input maps and output maps, eliminating the need to change
  273. back and forth between input and output windows. The column mapping is
  274. calculated when a map is opened and never changes. Attempting to change
  275. the input window while any input maps are open generates an error, as does
  276. attempting to change the output window while any output maps are open.
  277. Also, certain functions assume the existence of a single window, e.g.
  278. Rast_get_window(), Rast_window_{rows,cols}(). These functions still exist,
  279. and work so long as the windows aren't split (i.e. neither
  280. Rast_set_input_window() nor Rast_set_output_window() have been called, or
  281. the windows have since been joined by calling Rast_set_window()), but will
  282. generate an error if the windows are split. If the windows are split, the
  283. code must use e.g. Rast_get_input_window(), Rast_input_window_rows() etc
  284. to read the appropriate window.
  285. The "split window" design eliminates the most common reason for changing
  286. the window while maps are open, although there may be cases it doesn't
  287. cover (e.g. reading multiple input maps at different resolutions won't
  288. work). If we need to support that, there are a number of possible
  289. solutions.
  290. One is to store the current window in the fileinfo structure whenever the
  291. column mapping is created, check that it matches the current window
  292. whenever Rast_read_row() etc is called, and either re-generate it or
  293. generate an error if it differs. This avoids having to needlessly re-
  294. calculate the column mapping for all input maps on every set-window
  295. operation, but requires a window comparison (which probably needs some
  296. tolerance for comparing floating-point fields) for each get-row operation.
  297. Another is to allow each map to have a separate window, set from the
  298. current window when the map is opened. The main drawback is that
  299. Rast_window_rows() etc become meaningless. We would need to add yet
  300. another "level" of window splitting, so you'd have: single window,
  301. read/write windows, per-map windows.
  302. As usual, the main problem isn't implementation, but design and ensuring
  303. that existing code doesn't silently break (the current implementation
  304. should ensure that any breakage results in a fatal error).
  305. \section Raster_Category_File Raster Category File
  306. GRASS map layers have category labels associated with them. The
  307. category file is structured so that each category in the raster file
  308. can have a one-line description. The format of this file is described
  309. in \ref Raster_Category_File_Format.
  310. The routines described below manage the category file. Some of them
  311. use the <i>Categories</i> structure which is described in \ref
  312. GIS_Library_Data_Structures.
  313. \section Reading_and_Writing_the_Raster_Category_File Reading and Writing the Raster Category File
  314. The following routines read or write the category file itself:
  315. - Rast_read_cats()
  316. The category file for raster file is read into the <i>cats</i>
  317. structure. If there is an error reading the category file, a
  318. diagnostic message is printed and -1 is returned. Otherwise, 0 is
  319. returned.
  320. - Rast_write_cats()
  321. Writes the category file for the raster file in the current mapset
  322. from the <i>cats</i> structure. Returns 1 if successful. Otherwise, -1
  323. is returned (no diagnostic is printed).
  324. - Rast_get_title()
  325. If only the map layer title is needed, it is not necessary to read the
  326. entire category file into memory. This routine gets the title for
  327. raster file directly from the category file, and returns a pointer to
  328. the title. A legal pointer is always returned. If the map layer does
  329. not have a title, then a pointer to the empty string "" is returned.
  330. - Rast_put_title()
  331. If it is only desired to change the title for a map layer, it is not
  332. necessary to read the entire category file into memory, change the
  333. title, and rewrite the category file. This routine changes the title
  334. for the raster file in the current mapset directly in the category
  335. file. It returns a pointer to the title.
  336. \section Querying_and_Changing_the_Categories_Structure Querying and Changing the Categories Structure
  337. The following routines query or modify the information contained in
  338. the category structure:
  339. - Rast_get_cat()
  340. This routine looks up category in the cats structure and returns a
  341. pointer to a string which is the label for the category. A legal
  342. pointer is always returned. If the category does not exist in cats
  343. then a pointer to the empty string "" is returned.
  344. <b>Warning:</b> The pointer that is returned points to a hidden static
  345. buffer. Successive calls to Rast_get_cat() overwrite this buffer.
  346. - Rast_get_cats_title()
  347. Map layers store a one-line title in the category structure as
  348. well. This routine returns a pointer to the title contained in the
  349. cats structure. A legal pointer is always returned. If the map layer
  350. does not have a title, then a pointer to the empty string "" is
  351. returned.
  352. - Rast_init_cats()
  353. To construct a new category file, the structure must first be
  354. initialized. This routine initializes the cats structure, and copies
  355. the title into the structure.
  356. For example:
  357. \code
  358. struct Categories cats;
  359. Rast_init_cats ((CELL) 0, "", &cats);
  360. \endcode
  361. - Rast_set_cat()
  362. Copies the label into the cats structure for category.
  363. - Rast_set_cats_title()
  364. Copies the title is copied into the cats structure.
  365. - Rast_free_cats()
  366. Frees memory allocated by Rast_read_cats(), Rast_init_cats() and
  367. Rast_set_cat().
  368. \section Raster_Color_Table Raster Color Table
  369. GRASS map layers have colors associated with them. The color tables
  370. are structured so that each category in the raster file has its own
  371. color. The format of this file is described in
  372. \ref Raster_Color_Table_Format.
  373. The routines that manipulate the raster color file use the
  374. <i>Colors</i> structure which is described in detail in
  375. \ref GIS_Library_Data_Structures.
  376. \section Reading_and_Writing_the_Raster_Color_File Reading and Writing the Raster Color File
  377. The following routines read, create, modify, and write color tables.
  378. - Rast_read_colors()
  379. The color table for the raster file in the specified mapset is read
  380. into the <em>colors</em> structure. If the data layer has no color
  381. table, a default color table is generated and 0 is returned. If there
  382. is an error reading the color table, a diagnostic message is printed
  383. and -1 is returned. If the color table is read ok, 1 is returned.
  384. - Rast_write_colors()
  385. Write map layer color table. The color table is written for the raster
  386. file in the specified mapset from the <em>colors</em> structure. If
  387. there is an error, -1 is returned. No diagnostic is
  388. printed. Otherwise, 1 is returned.
  389. The <em>colors</em> structure must be created properly, i.e.,
  390. Rast_init_colors() to initialize the structure and Rast_add_color_rule() to
  391. set the category colors.
  392. <b>Note:</b> The calling sequence for this function deserves special
  393. attention. The <em>mapset</em> parameter seems to imply that it is
  394. possible to overwrite the color table for a raster file which is in
  395. another mapset. However, this is not what actually happens. It is very
  396. useful for users to create their own color tables for raster files in
  397. other mapsets, but without overwriting other users' color tables for
  398. the same raster file. If <em>mapset</em> is the current mapset, then
  399. the color file for <em>name</em> will be overwritten by the new color
  400. table. But if <em>mapset</em> is not the current mapset, then the
  401. color table is actually written in the current mapset under the
  402. <tt>colr2</tt> element as: <tt>colr2/mapset/name</tt>.
  403. \section Lookup_Up_Raster_Colors Lookup Up Raster Colors
  404. These routines translates raster values to their respective colors.
  405. - Rast_lookup_colors()
  406. Extracts colors for an array of raster values. The colors from the
  407. raster array are stored in the red, green, and blue arrays.
  408. <b>Note:</b> The red, green, and blue intensities will be in the range
  409. 0-255.
  410. - Rast_get_color()
  411. Get a category color. The red, green, and blue intensities for the
  412. color associated with category are extracted from the colors
  413. structure. The intensities will be in the range 0-255.
  414. \section Creating_and_or_Modifying_the_Color_Table Creating and/or Modifying the Color Table
  415. These routines allow the creation of customized color tables as well as the
  416. modification of existing tables.
  417. - Rast_init_colors()
  418. Initialize <i>colors</i> structure for subsequent calls
  419. Rast_add_color_rule() and Rast_set_color().
  420. - Rast_add_color_rule()
  421. This is the heart and soul of the color logic. It adds a color
  422. rule to the <em>colors</em> structure. The colors defined by the red,
  423. green, and blue values are assigned to the categories
  424. respectively. Colors for data values between two categories are not
  425. stored in the structure but are interpolated when queried by
  426. Rast_lookup_colors() and Rast_get_color(). The color components must be in the
  427. range 0-255.
  428. For example, to create a linear grey scale for the range 200-1000:
  429. \code
  430. struct Colors colr;
  431. Rast_init_colors (&colr) ;
  432. Rast_add_color_rule ((CELL) 200, 0,0,0,(CELL) 1000, 255,255,255) ;
  433. \endcode
  434. The programmer is encouraged to review \ref Raster_Color_Table_Format.
  435. <b>Note:</b> The <em>colors</em> structure must have been initialized
  436. by Rast_init_colors(). See \ref Predefined_Color_Tables for routines to
  437. build some predefined color tables.
  438. - Rast_set_color()
  439. Set a category color. The red, green, and blue intensities for the
  440. color associated with category The intensities must be in the range
  441. 0-255. Values below zero are set as zero, values above 255 are set as
  442. 255.
  443. <b>Warning:</b> Use of this routine is discouraged because it defeats
  444. the new color logic. It is provided only for backward
  445. compatibility. Overuse can create large color
  446. tables. Rast_add_color_rule() should be used whenever possible.
  447. <b>Note:</b> The <em>colors</em> structure must have been initialized
  448. by Rast_init_color().
  449. - Rast_get_color_range()
  450. - Rast_get_d_color_range()
  451. Get color range. Gets the minimum and maximum raster values that have
  452. colors associated with them.
  453. - Rast_free_colors()
  454. Free dynamically allocated memory associated with the <em>colors</em>
  455. structure.
  456. <b>Note:</b> This routine may be used after Rast_read_colors() as well as
  457. after Rast_init_colors().
  458. \section Predefined_Color_Tables Predefined Color Tables
  459. The following routines generate entire color tables. The tables are
  460. loaded into a <i>colors</i> structure based on a range of category
  461. values from minimum to maximum value. The range of values for a raster
  462. map can be obtained, for example, using Rast_read_range().
  463. <b>Note:</b> The color tables are generated without information about
  464. any particular raster file.
  465. These color tables may be created for a raster map, but they may also
  466. be generated for loading graphics colors. These routines return -1 if
  467. minimum value is greater than maximum value, 1 otherwise.
  468. - Rast_make_aspect_colors()
  469. Generates a color table for aspect data.
  470. - Rast_make_ramp_colors()
  471. Generates a color table with 3 sections: red only, green only, and
  472. blue only, each increasing from none to full intensity. This table is
  473. good for continuous data, such as elevation.
  474. - Rast_make_wave_colors()
  475. Generates a color table with 3 sections: red only, green only, and
  476. blue only, each increasing from none to full intensity and back down
  477. to none. This table is good for continuous data like elevation.
  478. - Rast_make_grey_scale_colors()
  479. Generates a grey scale color table. Each color is a level of grey,
  480. increasing from black to white.
  481. - Rast_make_rainbow_colors()
  482. Generates a "shifted" rainbow color table - yellow to green to cyan to
  483. blue to magenta to red. The color table is based on rainbow
  484. colors. (Normal rainbow colors are red, orange, yellow, green, blue,
  485. indigo, and violet.) This table is good for continuous data, such as
  486. elevation.
  487. - Rast_make_random_colors()
  488. Generates random colors. Good as a first pass at a color table for
  489. nominal data.
  490. - Rast_make_ryg_colors()
  491. Generates a color table that goes from red to yellow to green.
  492. - Rast_make_gyr_colors()
  493. Generates a color table that goes from green to yellow to red.
  494. - Rast_make_histogram_eq_colors()
  495. Generates a histogram contrast-stretched grey scale color table that goes
  496. from the, histogram information.
  497. \section Raster_History_File Raster History File
  498. The history file contains documentary information about the raster
  499. file: who created it, when it was created, what was the original data
  500. source, what information is contained in the raster file, etc.
  501. The following routines manage this file. They use the History
  502. structure which is described in \ref GIS_Library_Data_Structures.
  503. <b>Note:</b> This structure has existed relatively unmodified since
  504. the inception of GRASS. It is in need of overhaul. Programmers should
  505. be aware that future versions of GRASS may no longer support either
  506. the routines or the data structure which support the history file.
  507. - Rast_read_history()
  508. Reads raster history file. This routine reads the history file for the
  509. raster map into the History structure.
  510. - Rast_write_history()
  511. Writes raster history file. This routine writes the history file for
  512. the raster map in the current mapset from the History structure.
  513. <b>Note:</b> The History structure should first be
  514. initialized using Rast_short_history().
  515. - Rast_short_history()
  516. This routine initializes History structure, recording the date, user,
  517. module name and the raster map.
  518. <b>Note:</b> This routine only initializes the data structure. It does
  519. not write the history file.
  520. \section Raster_Range_File Raster Range File
  521. The following routines manage the raster range file. This file
  522. contains the minimum and maximum values found in the raster file. The
  523. format of this file is described in \ref Raster_Range_File_Format.
  524. The routines below use the <i>Range</i> data structure which is
  525. described in \ref GIS_Library_Data_Structures.
  526. - Rast_read_range()
  527. Reads raster range. This routine reads the range information for the
  528. raster map into the <i>range</i> structure. A diagnostic message is
  529. printed and -1 is returned if there is an error reading the range
  530. file. Otherwise, 0 is returned.
  531. - Rast_write_range()
  532. Write raster range file. This routine writes the range information for
  533. the raster map in the current mapset from the <i>range</i>
  534. structure. A diagnostic message is printed and -1 is returned if there
  535. is an error writing the range file. Otherwise, 0 is returned.
  536. The range structure must be initialized and updated using the following
  537. routines:
  538. - Rast_init_range()
  539. Initializes the <i>range</i> structure for updates by Rast_update_range()
  540. and Rast_row_update_range().
  541. - Rast_update_range()
  542. Compares the category value with the minimum and maximum values in the
  543. <i>range</i> structure, modifying the range if the value extends the
  544. range.
  545. - Rast_row_update_range()
  546. This routine updates the range data just like Rast_update_range().
  547. The range structure is queried using the following routine:
  548. - Rast_get_range_min_max()
  549. Get range minimum and maximum value.
  550. \section Raster_Histograms Raster Histograms
  551. The following routines provide a relatively efficient mechanism for
  552. computing and querying a histogram of raster data. They use the
  553. <b>Cell_stats</b> structure to hold the histogram information. The
  554. histogram is a count associated with each unique raster value
  555. representing the number of times each value was inserted into the
  556. structure.
  557. These next two routines are used to manage the Cell_stats structure:
  558. - Rast_init_cell_stats()
  559. Initialize cell stats, This routine, which must be called first,
  560. initializes the Cell_stats structure.
  561. - Rast_free_cell_stats()
  562. Free cell stats. The memory associated with structure is freed. This
  563. routine may be called any time after calling Rast_init_cell_stats().
  564. This next routine stores values in the histogram:
  565. - Rast_update_cell_stats()
  566. Adds data to cell stats. Once all values are stored, the structure may
  567. be queried either randomly (i.e., search for a specific raster value) or
  568. sequentially (retrieve all raster values, in ascending order, and
  569. their related count):
  570. - Rast_find_cell_stat()
  571. Random query of cell stats. This routine allows a random query of the
  572. Cell_stats structure. The routine returns 1 if <B>cat</B> was found in
  573. the structure, 0 otherwise.
  574. Sequential retrieval is accomplished using these next 2 routines:
  575. - Rast_rewind_cell_stats()
  576. Reset/rewind cell stats. The structure is rewound (i.e., positioned at
  577. the first raster category) so that sorted sequential retrieval can
  578. begin.
  579. - Rast_next_cell_stat()
  580. Retrieve sorted cell stats. Retrieves the next <i>cat, count</i>
  581. combination from the structure. Returns 0 if there are no more items,
  582. non-zero if there are more.
  583. For example:
  584. \code
  585. struct Cell_stats s;
  586. CELL cat;
  587. long count;
  588. /* updating s occurs here */
  589. Rast_rewind_cell_stats(&s);
  590. while(Rast_next_cell_stat(&cat, &count, &s))
  591. fprintf(stdout, "%ld %ld\n", (long) cat, count);
  592. \endcode
  593. \section GRASS_5_raster_API GRASS 5 raster API
  594. <em>Needs to be merged into above sections.</em>
  595. \subsection The_CELL_Data_Type The CELL Data Type
  596. GRASS integer raster map data is defined to be of type CELL. This data
  597. type is defined in the "gis.h" header file. Programmers must declare
  598. all variables and buffers which will hold raster data or category
  599. codes as type CELL. Under GRASS the CELL data type is declared to be
  600. "int", but the programmer should not assume this. What should be
  601. assumed is that CELL is a signed integer type. It may be changed
  602. sometime to short or long. This implies that use of CELL data with
  603. routines which do not know about this data type (e.g.,
  604. <tt>fprintf(stdout, ...), sscanf()</tt>, etc.) must use an
  605. intermediate variable of type long. To print a CELL value, it must be
  606. cast to long. For example:
  607. \code
  608. CELL c; /* raster value to be printed */
  609. /* some code to get a value for c */
  610. fprintf(stdout, "%ld\n", (long) c); /* cast c to long to print */
  611. \endcode
  612. To read a CELL value, for example from user typed input, it is
  613. necessary to read into a long variable, and then assign it to the CELL
  614. variable. For example (this example does not check for valid inputs,
  615. EOF, etc., which good code must do):
  616. \code
  617. char userbuf[128];
  618. CELL c;
  619. long x;
  620. fprintf (stdout, "Which category? "); /* prompt user */
  621. gets(userbuf); /* get user response * /
  622. sscanf (userbuf,"%ld", &x); /* scan category into long variable */
  623. c = (CELL) x; /* assign long value to CELL value */
  624. \endcode
  625. Of course, with GRASS library routines that are designed to handle the
  626. CELL type, this problem does not arise. It is only when CELL data must
  627. be used in routines which do not know about the CELL type, that the
  628. values must be cast to or from long.
  629. \subsection GRASS_5_raster_API_gish Changes to gis.h
  630. The "gis.h" contains 5 new items:
  631. \code
  632. typedef float FCELL;
  633. typedef double DCELL;
  634. typedef int RASTER_MAP_TYPE;
  635. #define CELL_TYPE 0
  636. #define FCELL_TYPE 1
  637. #define DCELL_TYPE 2
  638. \endcode
  639. Also "gis.h" contains the definitions for new structures:
  640. \code
  641. struct FPReclass;
  642. struct FPRange;
  643. struct Quant;
  644. \endcode
  645. Some of the old structures such as
  646. \code
  647. struct Categories
  648. struct Cell_stats;
  649. struct Range;
  650. struct _Color_Rule_;
  651. struct _Color_Info_;
  652. struct Colors;
  653. \endcode
  654. were modified, so it is very important to use functional interface to
  655. access and set elements of these structures instead of accessing
  656. elements of the structures directly. Because some former elements such
  657. as for example <tt>(struct Range range.pmin)</tt> do not exist
  658. anymore. It was made sure non of the former elements have different
  659. meaning, so that the programs which do access the old elements
  660. directly either do not compile or work exactly the same way as prior
  661. to change.
  662. \subsection NULL_value_functions NULL-value functions
  663. - Rast_set_null_value()
  664. Set NULL value. For raster type <tt>CELL_TYPE</tt> use
  665. Rast_set_c_null_value(), for <tt>FCELL_TYPE</tt> Rast_set_f_null_value(),
  666. and for <tt>DCELL_TYPE</tt> Rast_set_d_null_value().
  667. - Rast_insert_null_values()
  668. Insert NULL value. If raster type is <tt>CELL_TYPE</tt> calls
  669. Rast_insert_c_null_values(), <tt>FCELL_TYPE</tt> calls
  670. Rast_insert_f_null_values(), and <tt>DCELL_TYPE</tt> calls
  671. Rast_insert_d_null_values().
  672. - Rast_is_null_value()
  673. Check NULL value. If raster type is <tt>CELL_TYPE</tt>, calls
  674. Rast_is_c_null_value(), <tt>FCELL_TYPE</tt> calls
  675. Rast_is_f_null_value(), and <tt>DCELL_TYPE</tt> calls
  676. Rast_is_d_null_value().
  677. It isn't good enough to test for a particular NaN bit pattern since
  678. the machine code may change this bit pattern to a different NaN. The
  679. test will be
  680. \code
  681. if(fcell == 0.0) return 0;
  682. if(fcell > 0.0) return 0;
  683. if(fcell < 0.0) return 0;
  684. return 1;
  685. \endcode
  686. or (as suggested by Mark Line)
  687. \code
  688. return(FCELL != fcell) ;
  689. \endcode
  690. - Rast_allocate_null_buf()
  691. Allocates an array of char based on the number of columns in the
  692. current region.
  693. - Rast_get_null_value_row()
  694. Reads a row from NULL value bitmap file for the raster map open for
  695. read. If there is no bitmap file, then this routine simulates the read
  696. as follows: non-zero values in the raster map correspond to non-NULL;
  697. zero values correspond to NULL. When MASK exists, masked cells are set
  698. to null.
  699. \subsection Floating_point_and_type_independent_functions Floating-point and type-independent functions
  700. - Rast_maskfd()
  701. Test for current maskreturns file descriptor number if MASK is in use
  702. and -1 if no MASK is in use.
  703. - Rast_map_is_fp()
  704. Returns true(1) if raster map is a floating-point dataset; false(0)
  705. otherwise.
  706. - Rast_map_type()
  707. Returns the storage type for raster map:
  708. - <tt>CELL_TYPE</tt> for integer raster map
  709. - <tt>FCELL_TYPE</tt> for floating-point raster map
  710. - <tt>DCELL_TYPE</tt> for floating-point raster map (double precision)
  711. - Rast_open_new()
  712. Creates new raster map in the current mapset. Calls G_open_map_new()
  713. for raster type <tt>CELL_TYPE</tt>, G_open_fp_map_new() for
  714. floating-point raster map. The use of this routine by applications is
  715. discouraged since its use would override user preferences (what
  716. precision to use).
  717. - Rast_set_fp_type()
  718. This controls the storage type for floating-point raster maps. It
  719. affects subsequent calls to Rast_open_fp_new(). The <em>type</em>
  720. must be one of <tt>FCELL_TYPE</tt> (float) or <tt>DCELL_TYPE</tt>
  721. (double). The use of this routine by applications is discouraged since
  722. its use would override user preferences.
  723. - Rast_open_fp_new()
  724. Creates a new floating-point raster map (in <tt>.tmp</tt>) and returns
  725. a file descriptor. The storage type (float or double) is determined by
  726. the last call to Rast_set_fp_type() or the default (float - unless the
  727. GRASS environmental variable GRASS_FP_DOUBLE is set).
  728. - Rast_allocate_buf()
  729. - Rast_allocate_c_buf()
  730. - Rast_allocate_f_buf()
  731. - Rast_allocate_d_buf()
  732. Allocate an arrays of CELL, FCELL, or DCELL (depending on raster type)
  733. based on the number of columns in the current region.
  734. - Rast_incr_void_ptr()
  735. Advances void pointer by n bytes. Returns new pointer value. Useful
  736. in raster row processing loops, substitutes
  737. \code
  738. CELL *cell;
  739. cell += n;
  740. \endcode
  741. Now
  742. \code
  743. rast = Rast_incr_void_ptr(rast, Rast_raster_size(data_type));
  744. \endcode
  745. Where <i>rast</i> is void* and data_type is RASTER_MAP_TYPE can be
  746. used instead of rast++.) Very useful to generalize the row processing
  747. - loop (i.e. void * buf_ptr += Rast_raster_size(data_type))
  748. - Rast_raster_size()
  749. If <i>data_type</i> is CELL_TYPE, returns sizeof(CELL), for FCELL_TYPE
  750. returns sizeof(FCELL), and for <EM>data_type</EM> is DCELL_TYPE,
  751. returns sizeof(DCELL).
  752. - Rast_raster_cmp()
  753. Compares raster values.
  754. - Rast_raster_cpy()
  755. Copies raster values.
  756. - Rast_set_value_c()
  757. If Rast_is_c_null_value() is true, sets value to null value. Converts
  758. CELL value to raster data type value and stores the result. Used for
  759. assigning CELL values to raster cells of any type.
  760. - Rast_set_value_f()
  761. If Rast_is_f_null_value() is true, sets value to null value. Converts
  762. FCELL val to raster data type and stores the result. Used for
  763. assigning FCELL values to raster cells of any type.
  764. - Rast_set_value_d()
  765. If Rast_is_d_null_value() is true, sets value to null value. Converts
  766. DCELL val to raster data type and stores the result. Used for
  767. assigning DCELL values to raster cells of any type.
  768. - Rast_get_value_c()
  769. Retrieves the value of raster type, converts it to CELL type and
  770. returns the result. If null value is stored, returns CELL null
  771. value. Used for retreiving CELL values from raster cells of any type.
  772. Note: when data_type != CELL_TYPE, no quantization is used, only type conversion.
  773. - Rast_get_value_f()
  774. Retrieves the value of raster type, converts it to FCELL type and
  775. returns the result. If null value is stored, returns FCELL null
  776. value. Used for retreiving FCELL values from raster cells of any type.
  777. - Rast_get_value_d()
  778. Retrieves the value of raster type, converts it to DCELL type and
  779. returns the result. If null value is stored, returns DCELL null
  780. value. Used for retreiving DCELL values from raster cells of any type.
  781. - Rast_get_row ()
  782. For CELL_TYPE raster type calls Rast_get_c_row(), FCELL_TYPE calls
  783. Rast_get_f_row(), and DCELL_TYPE Rast_get_d_row().
  784. - Rast_get_row_nomask().
  785. Same as Rast_get_f_row() except no masking occurs.
  786. - Rast_get_f_row()
  787. Read a row from the raster map performing type conversions as
  788. necessary based on the actual storage type of the map. Masking,
  789. resampling into the current region. NULL-values are always embedded
  790. (never converted to a value).
  791. - Rast_get_f_row_nomask()
  792. Same as Rast_get_f_row() except no masking occurs.
  793. - Rast_get_d_row()
  794. Same as Rast_get_f_row() except that the array double.
  795. - Rast_get_d_row_nomask()
  796. Same as Rast_get_d_row() except no masking occurs.
  797. - Rast_get_c_row()
  798. Reads a row of raster data and leaves the NULL values intact. (As
  799. opposed to the deprecated function Rast_get_row() which converts NULL
  800. values to zero.)
  801. <b>Note:</b> When the raster map is old and null file doesn't exist,
  802. it is assumed that all 0-cells are no-data. When map is floating
  803. point, uses quant rules set explicitly by Rast_set_quant_rules or stored
  804. in map's quant file to convert floats to integers.
  805. - Rast_get_c_row_nomask()
  806. Same as Rast_get_c_row() except no masking occurs.
  807. - Rast_put_row()
  808. If raster type is CELL_TYPE, calls Rast_put_c_row(), if FCELL_TYPE, then calls Rast_put_f_row(), and for DCELL_TYPE, calls Rast_put_d_row().
  809. - Rast_put_f_row()
  810. Write the next row of the raster map performing type conversion to the
  811. actual storage type of the resultant map. Keep track of the range of
  812. floating-point values. Also writes the NULL-value bitmap from the
  813. NULL-values embedded in the data array.
  814. - Rast_put_d_row()
  815. Same as Rast_put_f_row() except that the array is double.
  816. - Rast_put_c_row()
  817. Writes a row of raster data and a row of the null-value bitmap, only
  818. treating NULL as NULL. (As opposed to the deprecated function
  819. Rast_put_row() which treats zero values also as NULL.)
  820. - Rast_zero_row()
  821. Depending on raster type zeroes out Rast_window_cols() CELLs, FCELLs, or
  822. DCELLs stored in cell buffer.
  823. - Rast_get_sample()
  824. Extracts a cell value from raster map at given position with nearest neighbor interpolation, bilinear interpolation or cubic interpolation.
  825. \section Upgrades_to_Raster_Functions Upgrades to Raster Functions (comparing to GRASS 4.x)
  826. These routines will be modified (internally) to work with
  827. floating-point and NULL-values.
  828. - Rast_close()
  829. If the map is a new floating point, move the <TT>.tmp</TT> file into
  830. the <TT>fcell</TT> element, create an empty file in the <TT>cell</TT>
  831. directory; write the floating-point range file; write a default
  832. quantization file quantization file is set here to round fp numbers
  833. (this is a default for now). Create an empty category file, with max
  834. cat = max value (for backwards compatibility). Move the <TT>.tmp</TT>
  835. NULL-value bitmap file to the <TT>cell_misc</TT> directory.
  836. - Rast_open_old()
  837. Arrange for the NULL-value bitmap to be read as well as the raster
  838. map. If no NULL-value bitmap exists, arrange for the production of
  839. NULL-values based on zeros in the raster map.
  840. If the map is floating-point, arrange for quantization to integer for
  841. Rast_get_c_row(), et. al., by reading the quantization rules for
  842. the map using Rast_read_quant().
  843. If the programmer wants to read the floating point map using uing
  844. quant rules other than the ones stored in map's quant file, he/she
  845. should call Rast_set_quant_rules() after the call to Rast_open_old().
  846. - Rast_get_row()
  847. If the map is floating-point, quantize the floating-point values to
  848. integer using the quantization rules established for the map when the
  849. map was opened for reading (this quantization is read from
  850. cell_misc/name/f_quant file, but can be reset after opening raster map
  851. by Rast_set_quant_rules()). NULL values are converted to zeros. <b>This
  852. routine is deprecated!!</b>
  853. - Rast_put_row()
  854. Zero values are converted to NULLs. Write a row of the NULL value bit
  855. map. <b>This routine is deprecated!!</b>
  856. \section Null_no_data NULL (no data) handling
  857. The <tt>null</tt> file is stored in <tt>cell_misc/name/null file</tt>.
  858. -2^31 (= 0x80000000 = -2147483648) is the null value for the CELL
  859. type, so you'll never see that value in a map.
  860. The FP nulls are the all-ones bit patterns. These corresponds to NaN
  861. according to the IEEE-754 formats, although it isn't the "default" NaN
  862. pattern generated by most architectures (which is usually 7fc00000 or
  863. ffc00000 for float and 7ff8000000000000 or fff8000000000000 for
  864. double, i.e. an all-ones exponent, the top-bit of the mantissa set,
  865. and either sign).
  866. So far as arithmetic is concerned, any value with an all-ones exponent
  867. and a non-zero mantissa is treated as NaN.
  868. Rast_set_d_null_value() and Rast_set_f_null_value() use the all-ones
  869. bit pattern. This is one of the many NaN values (anything with an
  870. all-ones exponent and a non-zero mantissa is NaN). As the topmost bit
  871. (i.e. the sign bit) is set, it is possible that some code would
  872. consider that to be "-NaN". E.g. code which writes a leading "-" based
  873. upon the sign bit before considering the other components would do so.
  874. Rast_is_d_null_value() and Rast_is_f_null_value() treat any NaN as
  875. null (specifically, they test whether the value is unequal to itself).
  876. At one time, these functions (or rather, their predecessors) checked
  877. explicitly for the all-ones pattern, but this was changed (in r33717
  878. and r33752) to improve robustness. Apart from code explicitly setting
  879. a value to "null", NaNs can arise from calculations (0.0/0.0, sqrt(x)
  880. or log(x) for x<0, asin(x) or acos(x) for abs(x)>1, etc), and there's
  881. no guarantee as to exactly which NaN representation will result.
  882. <b>Presence or absence of <tt>null</tt> file:</b>
  883. For an integer map, any cells which were null will become zero, but
  884. any zeroes (cells which were previously either null or zero) will be
  885. treated as nulls (this is for compatibility with GRASS 4.x, which
  886. didn't have a <tt>null</tt> file, but typically used zero to indicate
  887. a null value).
  888. For a floating-point map, any cells which were null will become zero
  889. (when writing FP data, a null has a zero written to the fcell/\<map\>
  890. file, and the corresponding bit is set in the <tt>null</tt> file).
  891. \section Color_Functions Color Functions (new and upgraded)
  892. \subsection Upgraded_Colors_structures Upgraded Colors structures
  893. \code
  894. struct _Color_Rule_
  895. {
  896. struct
  897. {
  898. int version; /* set by read_colors: -1=old,1=new */
  899. DCELL shift;
  900. int invert;
  901. int is_float; /* defined on floating point raster data? */
  902. int null_set; /* the colors for null are set? */
  903. unsigned char null_red, null_grn, null_blu;
  904. int undef_set; /* the colors for cells not in range are set? */
  905. unsigned char undef_red, undef_grn, undef_blu;
  906. struct _Color_Info_ fixed, modular;
  907. DCELL cmin, cmax;
  908. };
  909. \endcode
  910. \section New_functions_to_support_colors_for_floating_point New functions to support colors for floating-point
  911. - Rast_lookup_colors()
  912. If raster type is CELL_TYPE, calls Rast_lookup_colors(), if FCELL_TYPE,
  913. calls Rast_lookup_f_colors(), and for DCELL_TYPE
  914. Rast_lookup_d_colors().
  915. - Rast_lookup_c_colors()
  916. - Rast_lookup_f_colors()
  917. Converts the floating-point values in the float data array to their
  918. <em>r,g,b</em> color components. Embedded NULL-values are handled
  919. properly as well.
  920. - Rast_lookup_d_colors()
  921. Converts the floating-point values in the double data array to their
  922. <em>r,g,b</em> color components. Embedded NULL-values are handled
  923. properly as well.
  924. - Rast_add_color_rule()
  925. If raster type is CELL_TYPE, calls Rast_add_c_color_rule(), if
  926. FCELL_TYPE, calls Rast_add_f_color_rule(), and for DCELL_TYPE
  927. calls Rast_add_d_color_rule().
  928. - Rast_get_color()
  929. Looks up the rgb colors for the value in the color table.
  930. - Rast_mark_colors_as_fp()
  931. Sets a flag in the <em>colors</em> structure that indicates that these
  932. colors should only be looked up using floating-point raster data (not
  933. integer data).
  934. \section New_functions_to_support_a_colors_for_the_NULL_value New functions to support a color for the NULL-value
  935. - Rast_set_null_value_color()
  936. Sets the color (in <em>colors</em>) for the NULL-value to <em>r,g,b</em>.
  937. - Rast_get_null_value_color()
  938. Puts the red, green, and blue components of the color for the
  939. NULL-value into <em>r,g,b</em>.
  940. \section New_functions_to_support_a_default_color New functions to support a default color
  941. - Rast_set_default_color()
  942. Sets the default color (in <em>colors</em>) to <em>r,g,b</em>. This is
  943. the color for values which do not have an explicit rule.
  944. - Rast_get_default_color()
  945. Puts the red, green, and blue components of the <tt>"default"</tt>
  946. color into <em>r,g,b</em>.
  947. \section New_functions_to_support_treating_a_raster_layer_as_a_color_image New functions to support treating a raster layer as a color image
  948. - Rast_get_row_colors()
  949. Reads a row of raster data and converts it to red, green and blue
  950. components according to the colors.
  951. This provides a convenient way to treat a raster layer as a color
  952. image without having to explicitly cater for each of CELL, FCELL and
  953. DCELL types.
  954. \section Upgraded_color_functions Upgraded color functions
  955. - Rast_read_colors()
  956. This routine reads the rules from the color file. If the input raster
  957. map is is a floating-point map (FCELL or DCELL) it calls
  958. Rast_mark_colors_as_fp().
  959. - Rast_write_colors()
  960. The rules are written out using floating-point format, removing
  961. trailing zeros (possibly producing integers). The flag marking the
  962. colors as floating-point is <b>not</b> written.
  963. - Rast_get_colors_min_max()
  964. If the color table is marked as <tt>"float"</tt>, then return the
  965. minimum as -(255&#94;3 * 128) and the maximum as (255&#94;3 *
  966. 128). This is to simulate a very <em>large</em> range so that GRASS
  967. doesn't attempt to use <em>colormode float</em> to allow interactive
  968. toggling of colors.
  969. - Rast_lookup_colors()
  970. Modified to return a color for NULL-values.
  971. - Rast_get_color()
  972. Modified to return a color for the NULL-value.
  973. \section Changes_to_the_Colors_structure Changes to the Colors structure
  974. Modifications to the Colors structure to support colors for
  975. floating-point data and the NULL-value consist of
  976. - the _Color_Rule_ struct was changed to have DCELL value (instead of
  977. CELL cat) to have the range be floating-point values instead of
  978. integer cats.
  979. - a color for NULL was added
  980. - the special color for zero was eliminated
  981. - a default color for values which have no assigned color was added
  982. - a flag was added to the Colors structure to indicate if either the
  983. map itself is floating-point (If the map is integer and the floating
  984. point functions are used to lookup colors, the values are checked to
  985. see if they are integer, and if they are, the integer mechanism is
  986. used)
  987. - fp_lookup - a lookup table for floating point numbers is added. It
  988. orders the end points of fp intervals into array with a pointer to a
  989. color rule for each inteval, and the binary search is then used when
  990. looking up colors instead of linearly searching through all color
  991. rules.
  992. \section Changes_to_the_colr_file Changes to the \c colr file
  993. - The rules are written out using floating-point format, removing trailing zeros (possibly producing integers) . For example, to ramp from red to green for the range [1.3,5.0]:
  994. \verbatim
  995. 1.3:255:0:0 5:0:255:0
  996. \endverbatim
  997. - The NULL-value color is written as:
  998. \verbatim
  999. nv:red:grn:blu
  1000. \endverbatim
  1001. - The default color (for values that don't have an explicit rule) is written
  1002. as:
  1003. \verbatim
  1004. *:red:grn:blu
  1005. \endverbatim
  1006. \section Range_functions Range functions (new and upgraded)
  1007. \subsection Modified_range_functions Modified range functions
  1008. - Rast_read_range()
  1009. Old range file (those with 4 numbers) should treat zeros in this file
  1010. as NULL-values. New range files (those with just 2 numbers) should
  1011. treat these numbers as real data (zeros are real data in this case).
  1012. An empty range file indicates that the min, max are undefined. This is
  1013. a valid case, and the result should be an initialized range struct
  1014. with no defined min/max.
  1015. If the range file is missing and the map is a floating-point map, this
  1016. function will create a default range by calling
  1017. Rast_construct_default_range().
  1018. - Rast_init_range()
  1019. Must set a flag in the range structure that indicates that no min/max
  1020. have been defined - probably a "first" boolean flag.
  1021. - Rast_update_range()
  1022. NULL-values must be detected and ignored.
  1023. - Rast_get_range_min_max()
  1024. If the range structure has no defined min/max (first!=0) there will
  1025. not be a valid range. In this case the min and max returned must be
  1026. the NULL-value.
  1027. - Rast_write_range()
  1028. This routine only writes 2 numbers (min,max) to the range file,
  1029. instead of the 4 (pmin,pmax,nmin,nmax) previously written. If there is
  1030. no defined min,max, an empty file is written.
  1031. \section New_range_functions New range functions
  1032. - Rast_construct_default_range()
  1033. Sets the integer range to [1,255].
  1034. - Rast_read_range()
  1035. If raster type is CELL_TYPE, calls Rast_read_range(), otherwise calls
  1036. Rast_read_fp_range().
  1037. - Rast_read_fp_range()
  1038. Read the floating point range file <tt>f_range</tt>. This file is
  1039. written in binary using XDR format. If there is no defined min/max in
  1040. FPRange structure, an empty <tt>f_range</tt> file is created.
  1041. An empty range file indicates that the min, max are undefined. This is
  1042. a valid case, and the result should be an initialized range struct
  1043. with no defined min/max.
  1044. If the range file is missing and the map is a floating-point map, this
  1045. function will create a default range by calling
  1046. Rast_construct_default_range().
  1047. - Rast_init_range()
  1048. If raster type is CELL_TYPE, calls Rast_init_range(), otherwise calls
  1049. Rast_init_fp_range().
  1050. - Rast_init_fp_range()
  1051. Must set a flag in the range structure that indicates that no min/max
  1052. have been defined - probably a "first" boolean flag.
  1053. - Rast_update_f_range()
  1054. - Rast_update_d_range()
  1055. Updates the floating-point range from the values in NULL-values must
  1056. be detected and ignored.
  1057. - Rast_get_fp_range_min_max()
  1058. Extract the min/max from the FPRange structure. If the range structure
  1059. has no defined min/max (first!=0) there will not be a valid range. In
  1060. this case the min and max returned must be the NULL-value.
  1061. - Rast_write_fp_range()
  1062. Write the floating point range file <tt>f_range</tt>. This file is
  1063. written in binary using XDR format. If there is no defined min/max in
  1064. <EM>r</EM>, an empty <tt>f_range</tt> file is created.
  1065. \section New_and_Upgraded_Cell_stats_functions New and Upgraded Cell_stats functions
  1066. Modified Cell_stats functions to handle NULL-values:
  1067. - Rast_init_cell_stats()
  1068. Set the count for NULL-values to zero.
  1069. - Rast_update_cell_stats()
  1070. Look for NULLs and update the NULL-value count.
  1071. - Rast_next_cell_stat()
  1072. Do not return a record for the NULL-value.
  1073. - Rast_find_cell_stat()
  1074. Allow finding the count for the NULL-value.
  1075. - Rast_get_stats_for_null_value()
  1076. Get a number of null values from stats structure. Note: when reporting
  1077. values which appear in a map using Rast_next_cell_stats() , to get stats
  1078. for null, call Rast_get_stats_for_null_value() first, since
  1079. Rast_next_cell_stats() does not report stats for null.
  1080. \section New_Quantization_Functions New Quantization Functions
  1081. New functions to support quantization of floating-point to integer:
  1082. - Rast_write_quant()
  1083. Writes the <tt>f_quant</tt> file for the raster map. If
  1084. mapset==Rast_mapset() i.e. the map is in current mapset, then the
  1085. original quant file in <tt>cell_misc/map/f_quant</tt> is
  1086. written. Othewise is written into <tt>quant2/mapset/name</tt> (much
  1087. like colr2 element). This results in map&#64;mapset being read using
  1088. quant rules stored Rast_mapset(). See Rast_read_quant() for detailes.
  1089. - Rast_set_quant_rules()
  1090. Sets quant translation rules for raster map opened for reading. After
  1091. calling this function, Rast_get_c_row() and Rast_get_row() will
  1092. use defined rules (instead of using rules defined in map's quant file)
  1093. to convert floats to ints.
  1094. - Rast_read_quant()
  1095. Reads quantization rules for raster map and stores them in the
  1096. quantization structure. If the map is in another mapset, first checks
  1097. for quant2 table for this map in current mapset.
  1098. - Rast_quant_init()
  1099. Initializes the Quant struct.
  1100. - Rast_quant_free()
  1101. Frees any memory allocated in Quant structure and re-initializes the
  1102. structure by calling Rast_quant_init().
  1103. - Rast_quant_truncate()
  1104. Sets the quant rules to perform simple truncation on floats.
  1105. - Rast_quant_truncate()
  1106. Sets the quant rules to perform simple rounding on floats.
  1107. - Rast_quant_organize_fp_lookup()
  1108. Organizes fp_lookup table for faster (logarithmic) lookup time
  1109. Rast_quant_organize_fp_lookup() creates a list of min and max for each
  1110. quant rule, sorts this list, and stores the pointer to quant rule that
  1111. should be used in between any 2 numbers in this list Also it stores
  1112. extreme points for 2 infinite rules, if exist After the call to
  1113. Rast_quant_organize_fp_lookup() instead of linearly searching through
  1114. list of rules to find a rule to apply, quant lookup will perform a
  1115. binary search to find an interval containing floating point value, and
  1116. then use the rule associated with this interval. When the value
  1117. doesn't fall within any interval, check for the infinite rules.
  1118. - Rast_quant_add_rule()
  1119. Add the rule that the floating-point range produces an integer in the
  1120. range by linear interpolation. Rules that are added later have higher
  1121. precedence when searching. If any of of the values is the NULL-value,
  1122. this rule is not added and 0 is returned. Otherwise return 1. if the
  1123. fp_lookup is organized, destroy it.
  1124. - Rast_quant_set_positive_infinite_rule()
  1125. - Rast_quant_get_positive_infinite_rule()
  1126. This rule has lower precedence than rules added with Rast_quant_add_rule().
  1127. - Rast_quant_set_negative_infinite_rule()
  1128. This rule has lower precedence than rules added with Rast_quant_add_rule().
  1129. - Rast_quant_get_negative_infinite_rule()
  1130. - Rast_quant_get_limits()
  1131. Extracts the minimum and maximum floating-point and integer values
  1132. from all the rules.
  1133. - Rast_quant_nrules()
  1134. Returns the number of rules, excluding the negative and positive
  1135. "infinite" rules.
  1136. - Rast_quant_get_rule()
  1137. The order of the rules returned by increasing <i>n</i> is the order
  1138. in which the rules are applied when quantizing a value - the first
  1139. rule applicable is used.
  1140. - Rast_quant_get_cell_value()
  1141. - Rast_quant_perform_d()
  1142. - Rast_quant_perform_f()
  1143. These next two functions are convenience functions to allow applications to
  1144. easily create quantization rules other than the defaults:
  1145. - Rast_quantize_fp_map()
  1146. Writes the <tt>f_quant</tt> file for the raster map.
  1147. - Rast_quantize_fp_map_range()
  1148. Writes the <tt>f_quant</TT> file for the raster map with one rule.
  1149. \section Categories_Labeling_Functions Categories Labeling Functions (new and upgraded)
  1150. \subsection Upgraded_Categories_structure Upgraded Categories structure
  1151. All the new programs which are using Categories structure directly
  1152. have to be modified to use API functions to update and retrieve info
  1153. from Categories structure. Both new and old API function can be used,
  1154. since old functions still have exact same functionality (even though
  1155. internally they are implemented very differently). New function names
  1156. end with raster_cats(); old function names end with _cats().
  1157. We made sure that all old fields in Categories structure are either
  1158. missing in new Categories structure or have exactly the same
  1159. meaning. We did it so that the modules using Categories structure
  1160. directly either do not compile with new gis library or work exactly
  1161. the same as bnefore. A programmer might want to read the data in a
  1162. floating point map in a way that each cell value stores index of it's
  1163. category label and data range. The way to do it is to call
  1164. Rast_set_quant_rules() after opening the map.
  1165. This is helpful when trying to collect statistics (how many cells of
  1166. each category are in the map. (although there is another new mechanism
  1167. to collect such stats - see Rast_mark_cats()) . Another reason to
  1168. get a category index instead of fp values is that this index will be
  1169. the FID into GRASS-DBMS link. Also he can use Rast_get_ith_cat()
  1170. to get the category information for each cell using this index.
  1171. Here is the new Categories structure defined in gis.h:
  1172. \code
  1173. struct Categories
  1174. {
  1175. CELL ncats ; /* total number of categories */
  1176. CELL num ; /* the highest cell values. Only exists
  1177. for backwards compatibility = (CELL)
  1178. max_fp_values in quant rules */
  1179. char *title ; /* name of data layer */
  1180. char *fmt ; /* printf-like format to generate labels */
  1181. float m1 ; /* Multiplication coefficient 1 */
  1182. float a1 ; /* Addition coefficient 1 */
  1183. float m2 ; /* Multiplication coefficient 2 */
  1184. float a2 ; /* Addition coefficient 2 */
  1185. struct Quant q ; /* rules mapping cell values to index in
  1186. list of labels */
  1187. char **labels ; /* array of labels of size num */
  1188. int * marks ; /* was the value with this label was used? */
  1189. int nalloc;
  1190. int last_marked_rule ;
  1191. } ;
  1192. \endcode
  1193. \section Changes_to_the_cats_file Changes to the \c cats file
  1194. The format of explicit label entries is the same for integer maps.
  1195. \verbatim
  1196. cat:description
  1197. \endverbatim
  1198. In addition label entries of new format is supported for floating point maps.
  1199. \verbatim
  1200. val:descr (where val is a floating point number)
  1201. \endverbatim
  1202. or
  1203. \verbatim
  1204. val1:val2:descr (where val1, val2 is a floating point range)
  1205. \endverbatim
  1206. Internally the labels are stored for fp ranges of data. However when
  1207. the cats file is written, all the decimal zeros are stripped so that
  1208. integer values appear as integers in the file. Also if values are the
  1209. same, only 1 value is written (i.e. first format).
  1210. This way even though the old cats files will be processed differently
  1211. internally, the user or application programmer will not notice this
  1212. difference as long as the proper api is used and the elements of
  1213. Categories structure are not accessed directly without API calls.
  1214. \section Range_functions Range functions (new and upgraded)
  1215. \section New_Functions_to_read_write_access_and_modify_Categories_structure New Functions to read/write access and modify Categories structure
  1216. - Rast_read_cats()
  1217. Is the same as existing Rast_read_cats().
  1218. - Rast_copy_cats()
  1219. - Rast_get_cat()
  1220. - Rast_get_c_cat()
  1221. - Rast_get_f_cat()
  1222. - Rast_get_d_cat()
  1223. Returns pointer to a string describing category.
  1224. - Rast_set_cat()
  1225. - Rast_set_c_cat()
  1226. - Rast_set_f_cat()
  1227. - Rast_set_d_cat()
  1228. Adds the label for range in category structure.
  1229. - Rast_number_of_cats()
  1230. Returns the number of labels. DO NOT use Rast_number_of_cats() (it
  1231. returns max cat number).
  1232. - Rast_get_ith_cat()
  1233. - Rast_get_ith_c_cat()
  1234. - Rast_get_ith_f_cat()
  1235. - Rast_get_ith_d_cat()
  1236. Returns i-th description and i-th data range from the list of category
  1237. descriptions with corresponding data ranges.
  1238. - Rast_get_cats_title()
  1239. Returns pointer to a string with title.
  1240. - Rast_unmark_cats()
  1241. Sets marks for all categories to 0. This initializes Categories
  1242. structure for subsequent calls to Rast_mark_cats () for each row
  1243. of data, where non-zero mark for i-th label means that some of the
  1244. cells in rast_row are labeled with i-th label and fall into i-th data
  1245. range.
  1246. These marks help determine from the Categories structure which labels
  1247. were used and which weren't.
  1248. - Rast_get_next_marked_cat()
  1249. - Rast_get_next_marked_c_cat()
  1250. - Rast_get_next_marked_f_cat()
  1251. - Rast_get_next_marked_d_cat()
  1252. Finds the next label and corresponding data range in the list of
  1253. marked categories. The category (label + data range) is marked by
  1254. Rast_mark_cats(). End points of the data range are converted to
  1255. raster type and returned. The number of times value from i-th
  1256. cat. data range appeared so far is returned in stats. See
  1257. Rast_unmark_cats(), Rast_rewind_cats() and Rast_mark_cats
  1258. ().
  1259. - Rast_mark_cats()
  1260. - Rast_mark_c_cats()
  1261. - Rast_mark_f_cats()
  1262. - Rast_mark_d_cats()
  1263. Looks up the category label for each raster value in the raster row
  1264. (row of raster cell value) and updates the marks for labels found.
  1265. Note: non-zero mark for i-th label stores the number of of raster
  1266. cells read so far which are labeled with i-th label and fall into i-th
  1267. data range.
  1268. - Rast_rewind_cats()
  1269. After call to this function Rast_get_next_marked_cat() returns the
  1270. first marked cat label.
  1271. - Rast_init_cats()
  1272. Same as existing Rast_init_cats() only ncats argument is
  1273. missign. ncats has no meaning in new Categories structure and only
  1274. stores (int) largets data value for backwards compatibility.
  1275. - Rast_set_cats_fmt()
  1276. Same as existing Rast_set_cats_fmt().
  1277. - Rast_set_cats_title()
  1278. Same as existing Rast_set_cats_title().
  1279. - Rast_write_cats()
  1280. Same as existing Rast_write_cats().
  1281. - Rast_free_cats()
  1282. Same as existing Rast_free_cats().
  1283. \section Library_Functions_that_are_Deprecated Library Functions that are Deprecated
  1284. These functions are deprecated, since they imply that the application
  1285. that uses them has not been upgraded to handle NULL-values and should
  1286. be eliminated from GRASS code.
  1287. - Rast_get_row()
  1288. To be replaced by Rast_get_c_row().
  1289. - Rast_get_row_nomask()
  1290. To be replaced by Rast_get_c_row_nomask().
  1291. - Rast_put_row()
  1292. To be replaced by Rast_put_c_row().
  1293. These functions are deprecated, since they can not be upgraded to
  1294. support NULL-values, and should be eliminated from GRASS code.
  1295. - Rast_open_map_new_random()
  1296. - Rast_put_row_random()
  1297. <b>Also, no support for random writing of floating-point rasters will be provided.</b>
  1298. \section Guidelines_for_upgrading_GRASS_4_x_Modules Guidelines for upgrading GRASS 4.x Modules
  1299. - Modules that process raster maps as <em>continuous</em> data should
  1300. read raster maps as floating-point. Modules that process raster maps
  1301. as <em>nominal</em> data should read raster maps as integer.
  1302. <em>Exception:</em> Modules that process raster colors or the modules
  1303. which report on raster categories labels should either always read the
  1304. maps as floating-point, or read the maps as integer if the map is
  1305. integer and floating-point if the map is floating-point.
  1306. - The quantization of floating-point to integer should NOT change the
  1307. color table. The color lookup should have its own separate
  1308. quantization.
  1309. - The quantization of floating-point to integer should NOT change the
  1310. Categories table. The Categories structure should have its own
  1311. separate quantization.
  1312. - Modules that read or write floating-point raster maps should use
  1313. <tt>double</tt> (<tt>DCELL</tt>) arrays instead of <tt>float</tt>
  1314. (<tt>FCELL</tt>) arrays.
  1315. - Modues should process NULL values in a well defined (consistent)
  1316. manner. Modules that processed zero as the pseudo NULL-value should
  1317. be changed to use the true NULL-value for this and process zero as
  1318. normal value.
  1319. - Modules should process non-NULL values as normal numbers and not
  1320. treat any particular numbers (e.g. zero) as special.
  1321. \section Important_hints_for_upgrades_to_modules Important hints for upgrades to raster modules
  1322. In general modules that use Rast_get_row(). Should use
  1323. Rast_get_c_row() instead.
  1324. Modules that use Rast_put_row(). Should use Rast_put_c_row()
  1325. instead.
  1326. \section Loading_the_Raster_Library Loading the Raster Library
  1327. The library is loaded by specifying
  1328. \verbatim
  1329. $(RASTERLIB)
  1330. \endverbatim
  1331. in the <tt>Makefile</tt>.
  1332. \section listOfFunctions List of functions
  1333. <b>TODO: Reorder functions</b>
  1334. \subsection MemoryAllocation Memory allocation
  1335. - Rast_allocate_c_buf()
  1336. - Rast_allocate_f_buf()
  1337. - Rast_allocate_d_buf()
  1338. - Rast_allocate_null_buf()
  1339. TODO: used in r.null and r.support, why Rast__ and not Rast_?
  1340. - Rast__allocate_null_bits()
  1341. - Rast__null_bitstream_size()
  1342. \subsection RasterMask Raster Mask
  1343. - Rast_suppress_masking()
  1344. - Rast_unsuppress_masking()
  1345. \subsection RasterStatistics Raster statistics
  1346. - Rast_cell_size()
  1347. - Rast_init_cell_stats()
  1348. - Rast_update_cell_stats()
  1349. - Rast_find_cell_stat()
  1350. - Rast_rewind_cell_stats()
  1351. - Rast_next_cell_stat()
  1352. - Rast_get_stats_for_null_value()
  1353. - Rast_free_cell_stats()
  1354. - Rast_cell_stats_histo_eq()
  1355. - Rast_get_cell_title()
  1356. - Rast_cell_stats_histo_eq()
  1357. \subsection RasterCategories Raster category management
  1358. - Rast_read_cats()
  1359. - Rast_get_max_cat()
  1360. - Rast_get_cats_title()
  1361. - Rast_get_c_cat()
  1362. - Rast_get_f_cat()
  1363. - Rast_get_d_cat()
  1364. - Rast_get_cat()
  1365. - Rast_unmark_cats()
  1366. - Rast_mark_c_cats()
  1367. - Rast_mark_f_cats()
  1368. - Rast_mark_d_cats()
  1369. - Rast_mark_cats()
  1370. - Rast_rewind_cats()
  1371. - Rast_get_next_marked_d_cat()
  1372. - Rast_get_next_marked_f_cat()
  1373. - Rast_get_next_marked_c_cat()
  1374. - Rast_get_next_marked_cat()
  1375. - Rast_set_c_cat()
  1376. - Rast_set_f_cat()
  1377. - Rast_set_d_cat()
  1378. - Rast_write_cats()
  1379. - Rast_get_ith_d_cat()
  1380. - Rast_get_ith_f_cat()
  1381. - Rast_get_ith_c_cat()
  1382. - Rast_get_ith_cat()
  1383. - Rast_init_cats()
  1384. - Rast_set_cats_title()
  1385. - Rast_set_cats_fmt()
  1386. - Rast_free_cats()
  1387. - Rast_copy_cats()
  1388. - Rast_number_of_cats()
  1389. - Rast_sort_cats()
  1390. \subsection RasterFileManagement Raster file management
  1391. - Rast_close()
  1392. - Rast_unopen()
  1393. \subsection ColorFunctions Color functions
  1394. - Rast_make_ryg_colors()
  1395. - Rast_make_ryg_fp_colors()
  1396. - Rast_make_aspect_colors()
  1397. - Rast_make_aspect_fp_colors()
  1398. - Rast_make_byr_colors()
  1399. - Rast_make_byr_fp_colors()
  1400. - Rast_make_bgyr_colors()
  1401. - Rast_make_bgyr_fp_colors()
  1402. - Rast_make_byg_colors()
  1403. - Rast_make_byg_fp_colors()
  1404. - Rast_make_grey_scale_colors()
  1405. - Rast_make_grey_scale_fp_colors()
  1406. - Rast_make_gyr_colors()
  1407. - Rast_make_gyr_fp_colors()
  1408. - Rast_make_rainbow_colors()
  1409. - Rast_make_rainbow_fp_colors()
  1410. - Rast_make_ramp_colors()
  1411. - Rast_make_ramp_fp_colors()
  1412. - Rast_make_wave_colors()
  1413. - Rast_make_wave_fp_colors()
  1414. - Rast_free_colors()
  1415. - Rast_get_color()
  1416. - Rast_get_c_color()
  1417. - Rast_get_f_color()
  1418. - Rast_get_d_color()
  1419. - Rast_get_null_value_color()
  1420. - Rast_get_default_color()
  1421. - Rast_make_histogram_eq_colors()
  1422. - Rast_make_histogram_log_colors()
  1423. - Rast_init_colors()
  1424. - Rast_invert_colors()
  1425. - Rast_lookup_c_colors()
  1426. - Rast_lookup_f_colors()
  1427. - Rast_lookup_d_colors()
  1428. - Rast_lookup_colors()
  1429. - Rast_make_random_colors()
  1430. - Rast_set_c_color_range()
  1431. - Rast_set_d_color_range()
  1432. - Rast_get_c_color_range()
  1433. - Rast_get_d_color_range()
  1434. - Rast_read_colors()
  1435. - Rast_mark_colors_as_fp()
  1436. - Rast_remove_colors()
  1437. - Rast_add_d_color_rule()
  1438. - Rast_add_f_color_rule()
  1439. - Rast_add_c_color_rule()
  1440. - Rast_add_color_rule()
  1441. - Rast_add_modular_d_color_rule()
  1442. - Rast_add_modular_f_color_rule()
  1443. - Rast_add_modular_c_color_rule()
  1444. - Rast_add_modular_color_rule()
  1445. - Rast_colors_count()
  1446. - Rast_get_fp_color_rule()
  1447. - Rast_parse_color_rule()
  1448. - Rast_parse_color_rule_error()
  1449. - Rast_read_color_rule()
  1450. - Rast_read_color_rules()
  1451. - Rast_load_colors()
  1452. - Rast_load_fp_colors()
  1453. - Rast_make_colors()
  1454. - Rast_make_fp_colors()
  1455. - Rast_set_c_color()
  1456. - Rast_set_d_color()
  1457. - Rast_set_null_value_color()
  1458. - Rast_set_default_color()
  1459. - Rast_shift_c_colors()
  1460. - Rast_shift_d_colors()
  1461. - Rast_write_colors()
  1462. \subsection RasterFloatingPointManagement Raster floating point management
  1463. - Rast_fpreclass_clear()
  1464. - Rast_fpreclass_reset()
  1465. - Rast_fpreclass_init()
  1466. - Rast_fpreclass_set_domain()
  1467. - Rast_fpreclass_set_range()
  1468. - Rast_fpreclass_get_limits()
  1469. - Rast_fpreclass_nof_rules()
  1470. - Rast_fpreclass_get_ith_rule()
  1471. - Rast_fpreclass_set_neg_infinite_rule()
  1472. - Rast_fpreclass_get_neg_infinite_rule()
  1473. - Rast_fpreclass_set_pos_infinite_rule()
  1474. - Rast_fpreclass_get_pos_infinite_rule()
  1475. - Rast_fpreclass_add_rule()
  1476. - Rast_fpreclass_reverse_rule_order()
  1477. - Rast_fpreclass_get_cell_value()
  1478. - Rast_fpreclass_perform_di()
  1479. - Rast_fpreclass_perform_df()
  1480. - Rast_fpreclass_perform_dd()
  1481. - Rast_fpreclass_perform_fi()
  1482. - Rast_fpreclass_perform_ff()
  1483. - Rast_fpreclass_perform_fd()
  1484. - Rast_fpreclass_perform_ii()
  1485. - Rast_fpreclass_perform_if()
  1486. - Rast_fpreclass_perform_id()
  1487. \subsection RasterMapReading Raster map reading
  1488. - Rast_get_cellhd()
  1489. - Rast_get_row_nomask()
  1490. - Rast_get_c_row_nomask()
  1491. - Rast_get_f_row_nomask()
  1492. - Rast_get_d_row_nomask()
  1493. - Rast_get_row()
  1494. - Rast_get_c_row()
  1495. - Rast_get_f_row()
  1496. - Rast_get_d_row()
  1497. - Rast_get_null_value_row()
  1498. - Rast_get_row_colors()
  1499. \subsection RasterMapHistogram Raster map histogram
  1500. - Rast_histogram_eq()
  1501. - Rast_init_histogram()
  1502. - Rast_read_histogram()
  1503. - Rast_write_histogram()
  1504. - Rast_write_histogram_cs()
  1505. - Rast_make_histogram_cs()
  1506. - Rast_get_histogram_num()
  1507. - Rast_get_histogram_cat()
  1508. - Rast_get_histogram_count()
  1509. - Rast_free_histogram()
  1510. - Rast_sort_histogram()
  1511. - Rast_sort_histogram_by_count()
  1512. - Rast_remove_histogram()
  1513. - Rast_add_histogram()
  1514. - Rast_set_histogram()
  1515. - Rast_extend_histogram()
  1516. - Rast_zero_histogram()
  1517. - Rast_want_histogram()
  1518. \subsection RasterMapHistory Raster map history
  1519. - Rast_read_history()
  1520. - Rast_write_history()
  1521. - Rast_short_history()
  1522. - Rast_command_history()
  1523. \subsection RasterMapInterpolation Raster map interpolation
  1524. - Rast_interp_linear()
  1525. - Rast_interp_bilinear()
  1526. - Rast_interp_cubic()
  1527. - Rast_interp_bicubic()
  1528. \subsection RasterMapQuantization Raster map quantization
  1529. - Rast_quant_clear()
  1530. - Rast_quant_free()
  1531. - Rast_quant_init()
  1532. - Rast_quant_is_truncate()
  1533. - Rast_quant_is_round()
  1534. - Rast_quant_truncate()
  1535. - Rast_quant_round()
  1536. - Rast_quant_get_limits()
  1537. - Rast_quant_nof_rules()
  1538. - Rast_quant_get_ith_rule()
  1539. - Rast_quant_set_neg_infinite_rule()
  1540. - Rast_quant_get_neg_infinite_rule()
  1541. - Rast_quant_set_pos_infinite_rule()
  1542. - Rast_quant_get_pos_infinite_rule()
  1543. - Rast_quant_add_rule()
  1544. - Rast_quant_reverse_rule_order()
  1545. - Rast_quant_get_cell_value()
  1546. - Rast_quant_perform_d()
  1547. - Rast_quant_perform_f()
  1548. - Rast_quantize_fp_map()
  1549. - Rast_quantize_fp_map_range()
  1550. - Rast_write_quant()
  1551. - Rast_read_quant()
  1552. \subsection ToDo yet unsorted functions
  1553. - Rast_maskfd()
  1554. - Rast_mask_info()
  1555. - Rast_set_null_value()
  1556. - Rast_set_c_null_value()
  1557. - Rast_set_f_null_value()
  1558. - Rast_set_d_null_value()
  1559. - Rast_is_null_value()
  1560. - Rast_is_c_null_value()
  1561. - Rast_is_f_null_value()
  1562. - Rast_is_d_null_value()
  1563. - Rast_insert_null_values()
  1564. - Rast_insert_c_null_values()
  1565. - Rast_insert_f_null_values()
  1566. - Rast_insert_d_null_values()
  1567. - Rast_open_old()
  1568. - Rast_open_c_new()
  1569. - Rast_open_c_new_uncompressed()
  1570. - Rast_set_cell_format()
  1571. - Rast_get_cell_format()
  1572. - Rast_open_fp_new()
  1573. - Rast_open_fp_new_uncompressed()
  1574. - Rast_set_fp_type()
  1575. - Rast_map_is_fp()
  1576. - Rast_map_type()
  1577. - Rast_get_map_type()
  1578. - Rast_open_new()
  1579. - Rast_open_new_uncompressed()
  1580. - Rast_set_quant_rules()
  1581. - Rast_put_cellhd()
  1582. - Rast_put_row()
  1583. - Rast_put_c_row()
  1584. - Rast_put_f_row()
  1585. - Rast_put_d_row()
  1586. - Rast_put_cell_title()
  1587. - Rast_truncate_fp_map()
  1588. - Rast_round_fp_map()
  1589. - Rast_construct_default_range()
  1590. - Rast_read_fp_range()
  1591. - Rast_read_range()
  1592. - Rast_write_range()
  1593. - Rast_write_fp_range()
  1594. - Rast_update_range()
  1595. - Rast_update_fp_range()
  1596. - Rast_row_update_range()
  1597. - Rast_row_update_fp_range()
  1598. - Rast_init_range()
  1599. - Rast_get_range_min_max()
  1600. - Rast_init_fp_range()
  1601. - Rast_get_fp_range_min_max()
  1602. - Rast_raster_cmp()
  1603. - Rast_raster_cpy()
  1604. - Rast_set_c_value()
  1605. - Rast_set_f_value()
  1606. - Rast_set_d_value()
  1607. - Rast_get_c_value()
  1608. - Rast_get_f_value()
  1609. - Rast_get_d_value()
  1610. - Rast_read_units()
  1611. - Rast_read_vdatum()
  1612. - Rast_write_units()
  1613. - Rast_write_vdatum()
  1614. - Rast_is_reclass()
  1615. - Rast_is_reclassed_to()
  1616. - Rast_get_reclass()
  1617. - Rast_free_reclass()
  1618. - Rast_put_reclass()
  1619. - Rast_get_sample_nearest()
  1620. - Rast_get_sample_bilinear()
  1621. - Rast_get_sample_cubic()
  1622. - Rast_get_sample()
  1623. - Rast_zero_c_buf()
  1624. - Rast_zero_buf()
  1625. */