gisrasterlib.dox 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802
  1. /*! \page gisrasterlib Raster File Processing
  2. <!-- doxygenized from "GRASS 5 Programmer's Manual"
  3. by M. Neteler 2/2004, 8/2005, 2006
  4. -->
  5. \section gisrastintro GRASS Raster File Processing
  6. <P>
  7. <B>TODO: this sections needs to be cleaned up. The upper GRASS 4.x
  8. and the lower GRASS 5.x/6.x parts need to me merged.
  9. </B>
  10. - \subpage gisrastintro
  11. - \subpage Opening_an_Existing_Raster_File
  12. - \subpage Creating_and_Opening_New_Raster_Files
  13. - \subpage Allocating_Raster_I_O_Buffers
  14. - \subpage Reading_Raster_Files
  15. - \subpage Raster_Map_Layer_Support_Routines
  16. - \subpage Raster_Header_File
  17. - \subpage Raster_Category_File
  18. - \subpage Reading_and_Writing_the_Raster_Category_File
  19. - \subpage Querying_and_Changing_the_Categories_Structure
  20. - \subpage Raster_Color_Table
  21. - \subpage Reading_and_Writing_the_Raster_Color_File
  22. - \subpage Lookup_Up_Raster_Colors
  23. - \subpage Creating_and_or_Modifying_the_Color_Table
  24. - \subpage Predefined_Color_Tables
  25. - \subpage Raster_History_File
  26. - \subpage Raster_Range_File
  27. - \subpage Raster_Histograms
  28. - \subpage GRASS_5_raster_API
  29. - \subpage Upgrades_to_Raster_Functions
  30. - \subpage Null_no_data
  31. - \subpage Color_Functions
  32. - \subpage New_functions_to_support_colors_for_floating_point
  33. - \subpage New_functions_to_support_a_colors_for_the_NULL_value
  34. - \subpage New_functions_to_support_a_default_color
  35. - \subpage New_functions_to_support_treating_a_raster_layer_as_a_color_image
  36. - \subpage Upgraded_color_functions
  37. - \subpage Changes_to_the_Colors_structure
  38. - \subpage Changes_to_the_colr_file
  39. - \subpage Range_functions
  40. - \subpage New_range_functions
  41. - \subpage New_and_Upgraded_Cell_stats_functions
  42. - \subpage New_Quantization_Functions
  43. - \subpage Categories_Labeling_Functions
  44. - \subpage Changes_to_the_cats_file
  45. - \subpage Range_functions
  46. - \subpage New_Functions_to_read_write_access_and_modify_Categories_structure
  47. - \subpage Library_Functions_that_are_Deprecated
  48. - \subpage Guidelines_for_upgrading_GRASS_4_x_Modules
  49. - \subpage Important_hints_for_upgrades_to_raster_modules
  50. <P>
  51. Raster files are the heart and soul of GRASS (update 2005: meanwhile also
  52. vector data processing entered GRASS' heart). Because of this, a
  53. suite of routines which process raster file data has been
  54. provided. The processing of raster files consists of determining which
  55. raster file or files are to be processed (either by prompting the user
  56. or as specified on the module command line), locating the raster file
  57. in the database, opening the raster file, dynamically allocating i/o
  58. buffers, reading or writing the raster file, closing the raster file,
  59. and creating support files for newly created raster files.
  60. <P>
  61. Raster file data can be of type CELL, FCELL or DCELL, they are defined
  62. in "gis.h". CELL is a 32-bit signed integer, FCELL is an IEEE single-precision
  63. floating-point, and DCELL is an IEEE double-precision floating-point.
  64. G3D (GRID3D) is treated as DCELL.
  65. <P>
  66. Prompting for Raster Files</A>
  67. <P>
  68. The following routines interactively prompt the user for a raster file
  69. name. In each, the <B>prompt</B> string will be printed as the first
  70. line of the full prompt which asks the user to enter a raster file
  71. name. If <B>prompt</B> is the empty string "" then an appropriate
  72. prompt will be substituted. The name that the user enters is copied
  73. into the <B>name</B> buffer (The size of name should be large enough
  74. to hold any GRASS file name. Most systems allow file names to be quite
  75. long. It is recommended that name be declared char name.) These
  76. routines have a built-in 'list' capability which allows the user to
  77. get a list of existing raster files.
  78. <P> The user is required to enter a valid raster file name, or else
  79. hit the RETURN key to cancel the request. If the user enters an
  80. invalid response, a message is printed, and the user is prompted
  81. again. If the user cancels the request, the NULL pointer is
  82. returned. Otherwise the mapset where the raster file lives or is to be
  83. created is returned. Both the name and the mapset are used in other
  84. routines to refer to the raster file.
  85. <P>
  86. char * G_ask_cell_old(char *prompt, char *name) prompt for existing
  87. raster file
  88. Asks the user to enter the name of an existing raster file in any
  89. mapset in the database.
  90. <P> char * G_ask_cell_in_mapset(char *prompt, char *name) prompt for
  91. existing raster file
  92. Asks the user to enter the name of an existing raster file in the
  93. current mapset.
  94. <P> char * G_ask_cell_new(char *prompt, char *name) prompt for new
  95. raster file
  96. Asks the user to enter a name for a raster file which does not exist
  97. in the current mapset.
  98. <P> Here is an example of how to use these routines. Note that the
  99. programmer must handle the NULL return properly:
  100. \verbatim
  101. char *mapset;
  102. char name[GNAME_MAX];
  103. mapset = G_ask_cell_old("Enter raster file to be processed", name);
  104. if (mapset == NULL)
  105. return(0);
  106. \endverbatim
  107. \subsection Finding_Raster_Files_in_the_Database Finding Raster Files
  108. in the Database
  109. <P>
  110. Noninteractive modules cannot make use of the interactive prompting
  111. routines described above. For example, a command line driven module
  112. may require a raster file name as one of the command arguments. GRASS
  113. allows the user to specify raster file names (or any other database
  114. file) either as a simple unqualified name, such as "soils", or as a
  115. fully qualified name, such as "soils@<I>mapset</I>", where
  116. <I>mapset</I> is the mapset where the raster file is to be
  117. found. Often only the unqualified raster file name is provided on the
  118. command line.
  119. <P>
  120. The following routines search the database for raster files:
  121. <P>
  122. char * G_find_cell(char *name, char *mapset) find a raster file
  123. Looks for the raster file <B>name</B> in the database. The
  124. <B>mapset</B> parameter can either be the empty string "", which means
  125. search all the mapsets in the user's current mapset search path, or it
  126. can be a specific mapset name, which means look for the raster file
  127. only in this one mapset (for example, in the current mapset) . If
  128. found, the mapset where the raster file lives is returned. If not
  129. found, the NULL pointer is returned.
  130. <P>
  131. If the user specifies a fully qualified raster file which exists, then
  132. <I>G_find_cell() </I> modifies <B>name</B> by removing the
  133. "@<I>mapset</I>".
  134. <P>
  135. For example, to find a raster file anywhere in the database:
  136. \verbatim
  137. char name[GNAME_MAX];
  138. char *mapset;
  139. if ((mapset = G_find_cell(name,"")) == NULL)
  140. /* not found */
  141. \endverbatim
  142. <P>
  143. To check that the raster file exists in the current mapset:
  144. \verbatim
  145. char name[GNAME_MAX];
  146. if (G_find_cell(name,G_mapset()) == NULL)
  147. /* not found */
  148. \endverbatim
  149. <P>
  150. \section Opening_an_Existing_Raster_File Opening an Existing Raster File
  151. <P>
  152. The following routine opens the raster file <B>name</B> in <B>mapset</B> for
  153. reading.
  154. <P>
  155. The raster file <B>name</B> and <B>mapset</B> can be obtained
  156. interactively using <I>G_ask_cell_old()</I> or <I>
  157. G_ask_cell_in_mapset()</I>, and noninteractively using <I>
  158. G_find_cell()</I>.
  159. <P>
  160. int G_open_cell_old(char *name, char *mapset) open an existing
  161. raster file
  162. This routine opens the raster file <B>name</B> in <B>mapset</B> for
  163. reading. A nonnegative file descriptor is returned if the open is
  164. successful. Otherwise a diagnostic message is printed and a negative
  165. value is returned. This routine does quite a bit of work. Since GRASS
  166. users expect that all raster files will be resampled into the current
  167. region, the resampling index for the raster file is prepared by this
  168. routine after the file is opened. The resampling is based on the
  169. active module region. Preparation required for reading the various
  170. raster file formats is also done.
  171. <P>
  172. \section Creating_and_Opening_New_Raster_Files Creating and Opening New Raster Files
  173. ####################
  174. <P>
  175. The following routines create the new raster file <B>name</B> in the
  176. current mapset [footnote] and open
  177. it for writing. The raster file <B>name</B> should be obtained
  178. interactively using <I>G_ask_cell_new.</I> If obtained
  179. noninteractively (e.g., from the command line) ,
  180. <I>G_legal_filename</I> should be called first to make sure that
  181. <B>name</B> is a valid GRASS file name.
  182. <P>
  183. <B>Note.</B> It is not an error for <B>name</B> to already exist. New
  184. raster files are actually created as temporary files and moved into the cell
  185. directory when closed. This allows an existing raster file to be read at the
  186. same time that it is being rewritten. The interactive routine
  187. <I>G_ask_cell_new</I> guarantees that <B>name</B> will not exist, but
  188. if <B>name</B> is obtained from the command line, <B>name</B> may exist.
  189. In this case <I>G_find_cell</I> could be used to see if <B>name</B> exists.
  190. <P>
  191. <B>Warning.</B> However, there is a subtle trap. The temporary file, which
  192. is created using <I>G_tempfile</I>, is named using the current process
  193. id. If the new raster file is opened by a parent process which exits after
  194. creating a child process using fork(), [footnote]
  195. the raster file may never get created since the temporary file
  196. would be associated with the parent process, not the child. GRASS management
  197. automatically removes temporary files associated with processes that are no
  198. longer running. If fork() must be used, the safest course of action is to
  199. create the child first, then open the raster file. (See the discussion under
  200. <I>G_tempfile()</I> for more details.)
  201. <P>
  202. FILE * G_open_cell_new(char *name) open a new raster file
  203. (sequential) Creates and opens the raster file <B>name</B> for writing by
  204. <I>G_put_map_row</I> which writes the file row by row in sequential
  205. order. The raster file data will be compressed as it is written.
  206. <P>
  207. A nonnegative file descriptor is returned if the open is successful.
  208. Otherwise a diagnostic message is printed and a negative value is returned.
  209. <P>
  210. FILE * G_open_cell_new_random(char *name) open a new raster file
  211. (random) Creates and opens the raster file <B>name</B> for writing by
  212. <I>G_put_map_row_random</I> which allows writing the raster file in a
  213. random fashion. The file will be created uncompressed. [footnote]
  214. <P>
  215. A nonnegative file descriptor is returned if the open is successful.
  216. Otherwise a diagnostic message is printed and a negative value is returned.
  217. <P>
  218. FILE * G_open_cell_new_uncompressed(char *nameopen a new raster
  219. file (uncompressed) Creates and opens the raster file <B>name</B> for
  220. writing by <I>G_put_map_row</I> which writes the file row by row in
  221. sequential order. The raster file will be in uncompressed format when closed.
  222. <P>
  223. A nonnegative file descriptor is returned if the open is successful.
  224. Otherwise a warning message is printed on stderr and a negative value is
  225. returned.
  226. <P>
  227. General use of this routine is not recommended. [footnote]
  228. This routine is provided so the
  229. <I>r.compress module</I> can create uncompressed raster files.
  230. <P>
  231. \section Allocating_Raster_I_O_Buffers Allocating Raster I/O Buffers
  232. <P>
  233. Since there is no predefined limit for the number of columns in the
  234. region,[footnote]
  235. buffers which are used for reading and writing raster data must be
  236. dynamically allocated.
  237. <P>
  238. CELL * G_allocate_cell_buf(void) allocate a raster buffer This
  239. routine allocates a buffer of type CELL just large enough to hold one row of
  240. raster data (based on the number of columns in the active region).
  241. \verbatim
  242. CELL *cell;
  243. cell = G_allocate_cell_buf(void) ;
  244. \endverbatim
  245. <P>
  246. If larger buffers are required, the routine <I>G_malloc</I> can be used.
  247. <P>
  248. If sufficient memory is not available, an error message is printed and exit()
  249. is called.
  250. <P>
  251. int G_zero_cell_buf(CELL *buf) zero a raster buffer This
  252. routines assigns each member of the raster buffer array <B>buf</B> to zero.
  253. It assumes that <B>buf</B> has been allocated using
  254. <I>G_allocate_cell_buf.</I>
  255. <P>
  256. \section Reading_Raster_Files Reading Raster Files
  257. Needs updating for GRASS 5!! See later in this file.
  258. <BR>
  259. <P>
  260. Raster data can be thought of as a two-dimensional matrix. The routines
  261. described below read one full row of the matrix. It should be understood,
  262. however, that the number of rows and columns in the matrix is determined by the
  263. region, not the raster file itself. Raster data is always read resampled into
  264. the region. [footnote]
  265. This allows the user to specify the coverage of
  266. the database during analyses. It also allows databases to consist of raster
  267. files which do not cover exactly the same area, or do not have the same grid
  268. cell resolution. When raster files are resampled into the region, they all
  269. "look" the same.
  270. <P>
  271. <B>Note.</B> The rows and columns are specified "C style", i.e.,
  272. starting with 0.
  273. <P>
  274. <P><P>
  275. <BR>
  276. THIS FUNCTION IS DEPRECATED IN GRASS 5! SEE NEXT CHAPTER!
  277. <P>
  278. int G_get_map_row (int fd, CELL *cell, int row) read a raster file
  279. This routine reads the specified <B>row</B> from the raster file open on
  280. file descriptor <B>fd</B> (as returned by <I>G_open_cell_old</I>) into
  281. the <B>cell</B> buffer. The <B>cell</B> buffer must be dynamically
  282. allocated large enough to hold one full row of raster data. It can be
  283. <I>allocated using G_allocate_cell_buf.</I>
  284. <P>
  285. This routine prints a diagnostic message and returns -1 if there is an error
  286. reading the raster file. Otherwise a nonnegative value is returned.
  287. <P>
  288. int G_get_map_row_nomask (int fd, CELL *cell, int row) read a
  289. raster file (without masking) This routine reads the specified <B>row</B>
  290. from the raster file open on file descriptor <B>fd</B> into the
  291. <B>cell</B> buffer like G_get_map_row() does. The difference is that
  292. masking is suppressed. If the user has a mask set, G_get_map_row() will
  293. apply the mask but G_get_map_row_nomask() will ignore it.
  294. <P>
  295. This routine prints a diagnostic message and returns -1 if there is an error
  296. reading the raster file. Otherwise a nonnegative value is returned.
  297. <P>
  298. <B>Note.</B> Ignoring the mask is not generally acceptable. Users expect
  299. the mask to be applied. However, in some cases ignoring the mask is
  300. justified. For example, the GRASS modules <I>r.describe</I>, which reads
  301. the raster file directly to report all data values in a raster file, and
  302. <I>r.slope.aspect</I>, which produces slope and aspect from elevation,
  303. ignore both the mask and the region. However, the number of GRASS modules
  304. which do this should be minimal. See Mask for more information
  305. about the mask.
  306. <P>
  307. \subsection Writing_Raster_Files Writing Raster Files
  308. Needs updating for GRASS 5!! See later in this file.
  309. <BR>
  310. <P>
  311. The routines described here write raster file data.
  312. <P>
  313. int G_put_map_row (int fd, CELL *buf) write a raster file
  314. (sequential) This routine writes one row of raster data from <B>buf</B> to
  315. the raster file open on file descriptor <B>fd.</B> The raster file must
  316. have been opened with <I>G_open_cell_new.</I>
  317. <P>
  318. The cell <B>buf</B> must have been allocated large enough for the region,
  319. perhaps using <I>G_allocate_cell_buf.</I>
  320. <P>
  321. If there is an error writing the raster file, a warning message is printed
  322. and -1 is returned. Otherwise 1 is returned.
  323. <P>
  324. <B>Note.</B> The rows are written in sequential order. The first call
  325. writes row 0, the second writes row 1, etc. The following example assumes
  326. that the raster file <B>name</B> is to be created:
  327. <P>
  328. \verbatim
  329. int fd, row, nrows, ncols;
  330. CELL *buf;
  331. fd = G_ope... /*...data for the row */
  332. G_put_map_row(fd, buf) ;
  333. \endverbatim
  334. <P>
  335. int G_put_map_row_random (int fd, CELL *buf, int row, int col, int
  336. ncells) write a raster file (random) This routine allows random writes to
  337. the raster file open on file descriptor <B>fd.</B> The raster file must
  338. have been opened using <I>G_open_cell_new_random.</I> The raster buffer
  339. <B>buf</B> contains <B>ncells</B> columns of data and is to be written
  340. into the raster file at the specified <B>row</B>, starting at column
  341. <B>col.</B>
  342. <P>
  343. \subsection Closing_Raster_Files Closing Raster Files
  344. <P>
  345. All raster files are closed by one of the following routines, whether opened
  346. for reading or for writing.
  347. <P>
  348. int G_close_cell (int fd) close a raster file The raster file
  349. opened on file descriptor <B>fd</B> is closed. Memory allocated for raster
  350. processing is freed. If open for writing, skeletal support files for the new
  351. raster file are created as well.
  352. <P>
  353. <B>Note.</B> If a module wants to explicitly write support files (e.g., a
  354. specific color table) for a raster file it creates, it must do so after the
  355. raster file is closed. Otherwise the close will overwrite the support files.
  356. See \ref Raster_Map_Layer_Support_Routines for routines which write
  357. raster support files.
  358. <P>
  359. int G_unopen_cell (int fd) unopen a raster file The raster file
  360. opened on file descriptor <B>fd</B> is closed. Memory allocated for raster
  361. processing is freed. If open for writing, the raster file is not created and
  362. the temporary file created when the raster file was opened is removed (see
  363. Creating_and_Opening_New_Raster_Files) .
  364. <P>
  365. This routine is useful when errors are detected and it is desired to not
  366. create the new raster file. While it is true that the raster file will not be
  367. created if the module exits without closing the file, the temporary file will
  368. not be removed at module exit. GRASS database management will eventually
  369. remove the temporary file, but the file can be quite large and will take up
  370. disk space until GRASS does remove it. Use this routine as a courtesy to the
  371. user.
  372. <P>
  373. \section Raster_Map_Layer_Support_Routines Raster Map Layer Support Routines
  374. <P>
  375. GRASS map layers have a number of support files associated with them. These
  376. files are discussed in detail in Raster_Maps. The support files
  377. are the <I>raster header</I>, the <I>category</I> file, the
  378. <I>color</I> table, the <I>history</I> file, and the <I>range</I> file.
  379. Each support file has its own data structure and associated routines.
  380. <P>
  381. \section Raster_Header_File Raster Header File
  382. <P>
  383. The raster header file contains information describing the geographic extent
  384. of the map layer, the grid cell resolution, and the format used to store the
  385. data in the raster file. The format of this file is described in
  386. Raster_Header_Format. The routines described below use the
  387. <I>Cell_head</I> structure which is shown in detail in
  388. GIS_Library_Data_Structures.
  389. <P>
  390. int G_get_cellhd(char *name, char *mapset, struct Cell_Head
  391. *cellhd) read the raster headerThe raster header for the raster file
  392. <B>name</B> in the specified <B>mapset</B> is read into the
  393. <B>cellhd</B> structure.
  394. <P>
  395. If there is an error reading the raster header file, a diagnostic message is
  396. printed and -1 is returned. Otherwise, 0 is returned.
  397. <P>
  398. <B>Note.</B> If the raster file is a reclass file, the raster header for
  399. the referenced raster file is read instead. See \ref Reclass_Format for
  400. information about reclass files, and <I>G_is_reclass</I> for
  401. distinguishing reclass files from regular raster files.
  402. <P>
  403. <B>Note.</B> It is not necessary to get the raster header for a map layer in
  404. order to read the raster file data. The routines which read raster file data
  405. automatically retrieve the raster header information and use it for resampling
  406. the raster file data into the active region. [footnote]
  407. If it is necessary to read the raster file directly
  408. without resampling into the active region, [footnote]
  409. then the raster header can be used to set the active region using
  410. <I>G_set_window.</I>
  411. <P>
  412. char * G_adjust_Cell_head(struct Cell_Head *cellhd, int rflag, int
  413. cflag) adjust cell headerThis function fills in missing parts of the input
  414. cell header (or region) . It also makes projection-specific adjustments. The
  415. <B>cellhd</B> structure must have its <I>north, south, east, west</I>,
  416. and <I>proj</I> fields set. If <B>rflag</B> is true, then the north-south
  417. resolution is computed from the number of <I>rows</I> in the
  418. <B>cellhd</B> structure. Otherwise the number of <I>rows</I> is computed
  419. from the north-south resolution in the structure, similarly for
  420. <B>cflag</B> and the number of columns and the east-west resolution. This
  421. routine returns NULL if execution occurs without error, otherwise it returns
  422. an error message.
  423. <P>
  424. char * G_put_cellhd(char *name, struct Cell_Head *cellhd) write
  425. the raster header This routine writes the information from the
  426. <B>cellhd</B> structure to the raster header file for the map layer
  427. <B>name</B> in the current mapset.
  428. <P>
  429. If there was an error creating the raster header, -1 is returned. No
  430. diagnostic is printed. Otherwise, 1 is returned to indicate success.
  431. <P>
  432. <B>Note.</B> Programmers should have no reason to use this routine. It is
  433. used by <I>G_close_cell</I> to giv e new raster files correct header
  434. files, and by the <I>r.support module</I> to give users a means of
  435. creating or modifying raster headers.
  436. <P>
  437. int G_is_reclass(char *name, char *mapset, char r_name, char
  438. **r_mapset) reclass file?This function determines if the raster file
  439. *<B>name</B> in <B>mapset</B> is a reclass file.
  440. If it is, then the name and mapset of the referenced
  441. raster file are copied into the <B>r_name</B> and <B>r_mapset</B>
  442. buffers.
  443. <P>
  444. Returns 1 if <B>name</B> is a reclass file, 0 if it is not, and -1 if
  445. there was a problem reading the raster header for <B>name.</B>
  446. <P>
  447. int G_is_reclassed_to(char *name, char *mapset, int *nrmaps,
  448. char ***rmaps) get child reclass maps listThis function generates a
  449. child reclass maps list from the cell_misc/reclassed_to file which stores
  450. this list. The cell_misc/reclassed_to file is written by
  451. G_put_reclass() .
  452. <P>
  453. G_is_reclassed_to() is used by g.rename, g.remove and r.reclass to
  454. prevent accidentally deleting the parent map of a reclassed raster map.
  455. <P>
  456. \section Raster_Category_File Raster Category File
  457. <P>
  458. GRASS map layers have category labels associated with them. The category file
  459. is structured so that each category in the raster file can have a one-line
  460. description. The format of this file is described in
  461. Raster_Category_File_Format.
  462. <P>
  463. The routines described below manage the category file. Some of them use the
  464. <I>Categories</I> structure which is described in
  465. GIS_Library_Data_Structures.
  466. <P>
  467. \section Reading_and_Writing_the_Raster_Category_File Reading and Writing the Raster Category File
  468. <P>
  469. The following routines read or write the category file itself:
  470. <P>
  471. int G_read_cats(char *name, char *mapset, struct Categories
  472. *cats) read raster category fileThe category file for raster file
  473. <B>name</B> in <B>mapset</B> is read into the <B>cats</B> structure. If
  474. there is an error reading the category file, a diagnostic message is printed
  475. and -1 is returned. Otherwise, 0 is returned.
  476. <P>
  477. int G_write_cats(char *name, struct Categories *cats) write raster
  478. category fileWrites the category file for the raster file <B>name</B> in
  479. the current mapset from the <B>cats</B> structure.
  480. <P>
  481. Returns 1 if successful. Otherwise, -1 is returned (no diagnostic is
  482. printed) .
  483. <P>
  484. char * G_get_cell_title(char *name, char *mapset) get raster map
  485. titleIf only the map layer title is needed, it is not necessary to read the
  486. entire category file into memory. This routine gets the title for raster file
  487. <B>name</B> in <B>mapset</B> directly from the category file, and returns
  488. a pointer to the title. A legal pointer is always returned. If the map layer
  489. does not have a title, then a pointer to the empty string "" is returned.
  490. <P>
  491. char * G_put_cell_title(char *name, char *title) change raster map
  492. titleIf it is only desired to change the title for a map layer, it is not
  493. necessary to read the entire category file into memory, change the title, and
  494. rewrite the category file. This routine changes the <B>title</B> for the
  495. raster file <B>name</B> in the current mapset directly in the category
  496. file. It returns a pointer to the title.
  497. <P>
  498. \section Querying_and_Changing_the_Categories_Structure Querying and Changing the Categories Structure
  499. <P>
  500. The following routines query or modify the information contained in the
  501. category structure:
  502. <P>
  503. char * G_get_cat(CELL n, struct Categories *cats) get a category
  504. labelThis routine looks up category <B>n</B> in the <B>cats</B>
  505. structure and returns a pointer to a string which is the label for the
  506. category. A legal pointer is always returned. If the category does not exist
  507. in <B>cats,</B> then a pointer to the empty string "" is returned.
  508. <P>
  509. <B>Warning.</B> The pointer that is returned points to a hidden static
  510. buffer. Successive calls to G_get_cat() overwrite this buffer.
  511. <P>
  512. char * G_get_cats_title (Categories *cats) get title from category
  513. structure structMap layers store a one-line title in the category structure
  514. as well. This routine returns a pointer to the title contained in the
  515. <B>cats</B> structure. A legal pointer is always returned. If the map
  516. layer does not have a title, then a pointer to the empty string "" is
  517. returned.
  518. <P>
  519. int G_init_cats(CELL n, char *title, struct Categories
  520. *cats) initialize category structureTo construct a new category file, the
  521. structure must first be initialized. This routine initializes the
  522. <B>cats</B> structure, and copies the <B>title</B> into the structure.
  523. The number of categories is set initially to <B>n.</B>
  524. <P>
  525. For example:
  526. <P>
  527. \verbatim
  528. struct Categories cats;
  529. G_init_cats ((CELL) 0, '''', &cats) ;
  530. \endverbatim
  531. <P>
  532. int G_set_cat(CELL n, char *label, struct Categories *cats) set a
  533. category labelThe <B>label</B> is copied into the <B>cats</B> structure
  534. for category <B>n.</B>
  535. <P>
  536. int G_set_cats_title(char *title, struct Categories *cats) set
  537. title in category structureThe <B>title</B> is copied into the
  538. <B>cats</B> structure.
  539. <P>
  540. int G_free_cats(struct Categories *cats) free category structure
  541. memoryFrees memory allocated by<I>G_read_cats, G_init_cats</I>
  542. and<I> G_set_cat.</I>
  543. <P>
  544. \section Raster_Color_Table Raster Color Table
  545. <P>
  546. GRASS map layers have colors associated with them. The color tables are
  547. structured so that each category in the raster file has its own color. The
  548. format of this file is described in Raster_Color_Table_Format.
  549. <P>
  550. The routines that manipulate the raster color file use the <I>Colors</I>
  551. structure which is described in detail in
  552. GIS_Library_Data_Structures.
  553. <P>
  554. \section Reading_and_Writing_the_Raster_Color_File Reading and Writing the Raster Color File
  555. <P>
  556. The following routines read, create, modify, and write color tables.
  557. <P>
  558. int G_read_colors(char *name, char *mapset, struct Colors
  559. *colors) read map layer color tableThe color table for the raster file
  560. <B>name</B> in the specified <B>mapset</B> is read into the
  561. <B>colors</B> structure.
  562. <P>
  563. If the data layer has no color table, a default color table is generated and
  564. 0 is returned. If there is an error reading the color table, a diagnostic
  565. message is printed and -1 is returned. If the color table is read ok, 1 is
  566. returned.
  567. <P>
  568. int G_write_colors(char *name, char *mapset, struct Colors
  569. *colors) write map layer color tableThe color table is written for the
  570. raster file <B>name</B> in the specified <B>mapset</B> from the
  571. <B>colors</B> structure.
  572. <P>
  573. If there is an error, -1 is returned. No diagnostic is printed. Otherwise, 1
  574. is returned.
  575. <P>
  576. The <B>colors</B> structure must be created properly, i.e.,
  577. <I>G_init_colors</I> to initialize the structure and
  578. <I>G_add_color_rule</I> to set the category colors. [footnote]
  579. <P>
  580. <B>Note.</B> The calling sequence for this function deserves special
  581. attention. The <B>mapset</B> parameter seems to imply that it is possible
  582. to overwrite the color table for a raster file which is in another mapset.
  583. However, this is not what actually happens. It is very useful for users to
  584. create their own color tables for raster files in other mapsets, but without
  585. overwriting other users' color tables for the same raster file. If
  586. <B>mapset</B> is the current mapset, then the color file for <B>name</B>
  587. will be overwritten by the new color table. But if <B>mapset</B> is not the
  588. current mapset, then the color table is actually written in the current
  589. mapset under the <B>colr2</B> element as: colr2/mapset/name.
  590. <P>
  591. \section Lookup_Up_Raster_Colors Lookup Up Raster Colors
  592. <P>
  593. These routines translates raster values to their respective colors.
  594. <P>
  595. int G_lookup_colors(CELL *raster, unsigned char *red, unsigned char
  596. *green, unsigned char *blue, set, int n, struct Colors *colors) lookup an
  597. array of colorsExtracts colors for an array of <B>raster</B> values. The
  598. colors for the <B>n</B> values in the <B>raster</B> array are stored in
  599. the <B>red, green</B>, and <B>blue</B> arrays. The values in the
  600. <B>set</B> array will indicate if the corresponding <B>raster</B> value
  601. has a color or not (1 means it does, 0 means it does not) . The programmer
  602. must allocate the <B>red, green, blue</B>, and <B>set</B> arrays to be at
  603. least dimension <B>n.</B>
  604. <P>
  605. <B>Note.</B> The <B>red, green</B>, and <B>blue</B> intensities will be
  606. in the range 0 -­ 255.
  607. <P>
  608. int G_get_color(CELL cat, int *red, int *green, int *blue, struct
  609. Colors *colors) get a category colorThe <B>red, green</B>, and
  610. <B>blue</B> intensities for the color associated with category <B>cat</B>
  611. are extracted from the <B>colors</B> structure. The intensities will be in
  612. the range 0 ­- 255.
  613. <P>
  614. \section Creating_and_or_Modifying_the_Color_Table Creating and/or Modifying the Color Table
  615. <P>
  616. These routines allow the creation of customized color tables as well as the
  617. modification of existing tables.
  618. <P>
  619. int G_init_colors(struct Colors *colors) initialize color
  620. structureThe <B>colors</B> structure is initialized for subsequent calls
  621. to <I>G_add_color_rule</I> and<I>G_set_color.</I>
  622. <P>
  623. int G_add_color_rule(CELL cat1, int r1, int g1, int b1, CELL cat2,
  624. int r2, int g2, int b2, struct Colors *colors) set colorsThis is the heart
  625. and soul of the new color logic. It adds a color rule to the <B>colors</B>
  626. structure. The colors defined by the red, green, and blue values
  627. <B>r1,g1,b1</B> and <B>r2,g2,b2</B> are assigned to <B>cat1</B> and
  628. <B>cat2</B> respectively. Colors for data values between <B>cat1</B> and
  629. <B>cat2</B> are not stored in the structure but are interpolated when
  630. queried by <I>G_lookup_colors</I> and<I> G_get_color.</I> The color
  631. components <B>r1,g1,b1</B> and <B>r2,g2,b2</B> must be in the range
  632. 0 - 255.
  633. <P>
  634. For example, to create a linear grey scale for the range 200 - 1000:
  635. <P>
  636. \verbatim
  637. struct Colors colr;
  638. G_init_colors (&colr) ;
  639. G_add_color_rule ((CELL) 200, 0,0,0,(CELL) 1000, 255,255,255) ;
  640. \endverbatim
  641. <P>
  642. The programmer is encouraged to review Raster_Color_Table_Format how
  643. this routine fits into the 5.x raster color logic.
  644. <P>
  645. <B>Note.</B> The <B>colors</B> structure must have been initialized by
  646. <I>G_init_colors.</I> See \ref Predefined_Color_Tables for routines to
  647. build some predefined color tables.
  648. <P>
  649. int G_set_color(CELL cat, int red, int green, int blue, struct
  650. Colors *colors) set a category colorThe <B>red, green</B>, and
  651. <B>blue</B> intensities for the color associated with category <B>cat</B>
  652. are set in the <B>colors</B> structure. The intensities must be in the
  653. range 0 -­ 255. Values below zero are set as zero, values above 255 are set as
  654. 255.
  655. <P>
  656. <B>Use of this routine is discouraged because it defeats the new color
  657. logic.</B> It is provided only for backward compatibility. Overuse can create
  658. large color tables. <I>G_add_color_rule</I> should be used whenever
  659. possible.
  660. <P>
  661. <B>Note.</B> The <B>colors</B> structure must have been initialized by
  662. <I>G_init_color.</I>
  663. <P>
  664. int G_get_color_range(CELL *min, CELL *max, struct Colors
  665. *colors) get color rangeGets the minimum and maximum raster values that
  666. have colors associated with them.
  667. <P>
  668. int G_free_colors(struct Colors *colors) free color structure
  669. memoryThe dynamically allocated memory associated with the <B>colors</B>
  670. structure is freed.
  671. <P>
  672. <B>Note.</B> This routine may be used after <I>G_read_colors</I> as
  673. well as after <I>G_init_colors.</I>
  674. <P>
  675. \section Predefined_Color_Tables Predefined Color Tables
  676. <P>
  677. The following routines generate entire color tables. The tables are loaded into
  678. a <B>colors</B> structure based on a range of category values from
  679. <B>min</B> to <B>max.</B> The range of values for a raster map can be
  680. obtained, for example, using <I>G_read_range.</I> <B>Note.</B> The color
  681. tables are generated without information about any particular raster file.
  682. <P>
  683. These color tables may be created for a raster file, but they may also be
  684. generated for loading graphics colors.
  685. <P>
  686. These routines return -1 if <B>min</B> is greater than <B>max</B>, 1
  687. otherwise.
  688. <P>
  689. int G_make_aspect_colors(struct Colors *colors, CELL min, CELL
  690. max) make aspect colorsGenerates a color table for aspect data.
  691. <P>
  692. int G_make_ramp_colors(struct Colors *colors, CELL min, CELL
  693. max) make color rampGenerates a color table with 3 sections: red only,
  694. green only, and blue only, each increasing from none to full intensity. This
  695. table is good for continuous data, such as elevation.
  696. <P>
  697. int G_make_wave_colors(struct Colors *colors, CELL min, CELL
  698. max) make color waveGenerates a color table with 3 sections: red only,
  699. green only, and blue only, each increasing from none to full intensity and
  700. back down to none. This table is good for continuous data like elevation.
  701. <P>
  702. int G_make_grey_scale_colors(struct Colors *colors, CELL min, CELL
  703. max) make linear grey scaleGenerates a grey scale color table. Each color
  704. is a level of grey, increasing from black to white.
  705. <P>
  706. int G_make_rainbow_colors(struct Colors *colors, CELL min, CELL
  707. max) make rainbow colorsGenerates a "shifted" rainbow color table - yellow
  708. to green to cyan to blue to magenta to red. The color table is based on
  709. rainbow colors. (Normal rainbow colors are red, orange, yellow, green, blue,
  710. indigo, and violet.) This table is good for continuous data, such as
  711. elevation.
  712. <P>
  713. int G_make_random_colors(struct Colors *colors, CELL min, CELL
  714. max) make random colorsGenerates random colors. Good as a first pass at a
  715. color table for nominal data.
  716. <P>
  717. int G_make_ryg_colors(struct Colors *colors, CELL min, CELL
  718. max) make red,yellow,green colorsGenerates a color table that goes from
  719. red to yellow to green.
  720. <P>
  721. int G_make_gyr_colors(struct Colors *colors, CELL min, CELL
  722. max) make green,yellow,red colorsGenerates a color table that goes from
  723. green to yellow to red.
  724. <P>
  725. int G_make_histogram_eq_colors(struct Colors *colors, struct
  726. Cell_stats *s) make histogram-stretched grey colorsGenerates a histogram
  727. contrast-stretched grey scale color table that goes from the ,histogram
  728. information in the Cell_stats structure <B>s.</B> (See
  729. Raster_Histograms) .
  730. <P>
  731. \section Raster_History_File Raster History File
  732. <P>
  733. The history file contains documentary information about the raster file: who
  734. created it, when it was created, what was the original data source, what
  735. information is contained in the raster file, etc. This file is discussed in
  736. Raster_History_File_Format
  737. <P>
  738. The following routines manage this file. They use the <I>History</I>
  739. structure which is described in GIS_Library_Data_Structures.
  740. <P>
  741. <B>Note.</B> This structure has existed relatively unmodified since the
  742. inception of GRASS. It is in need of overhaul. Programmers should be aware that
  743. future versions of GRASS may no longer support either the routines or the data
  744. structure which support the history file.
  745. <P>
  746. int G_read_history(char *name, char *mapset, struct History
  747. *history) read raster history fileThis routine reads the history file for
  748. the raster file <B>name</B> in <B>mapset</B> into the <B>history</B>
  749. structure.
  750. <P>
  751. A diagnostic message is printed and -1 is returned if there is an error
  752. reading the history file. Otherwise, 0 is returned.
  753. <P>
  754. int G_write_history(char *name, struct History *history) write
  755. raster history fileThis routine writes the history file for the raster file
  756. <B>name</B> in the current mapset from the <B>history</B> structure.
  757. <P>
  758. A diagnostic message is printed and -1 is returned if there is an error
  759. writing the history file. Otherwise, 0 is returned.
  760. <P>
  761. <B>Note.</B> The <B>history</B> structure should first be initialized
  762. using <I>G_short_history.</I>
  763. <P>
  764. int G_short_history(char *name, char *type, struct History
  765. *history) initialize history structureThis routine initializes the
  766. <B>history</B> structure, recording the date, user, module name and the
  767. raster file <B>name</B> structure. The <B>type</B> is an anachronism from
  768. earlier versions of GRASS and should be specified as "raster".
  769. <P>
  770. <B>Note.</B> This routine only initializes the data structure. It does not
  771. write the history file.
  772. <P>
  773. \section Raster_Range_File Raster Range File
  774. <P>
  775. The following routines manage the raster range file. This file contains the
  776. minimum and maximum values found in the raster file. The format of this file is
  777. described in Raster_Range_File_Format.
  778. <P>
  779. The routines below use the <I>Range</I> data structure which is described in
  780. GIS_Library_Data_Structures.
  781. <P>
  782. int G_read_range(char *name, char *mapset, struct Range
  783. *range) read raster rangeThis routine reads the range information for the
  784. raster file <B>name</B> in <B>mapset</B> into the <B>range</B>
  785. structure.
  786. <P>
  787. A diagnostic message is printed and -1 is returned if there is an error
  788. reading the range file. Otherwise, 0 is returned.
  789. <P>
  790. int G_write_range(char *name, struct Range *range) write raster
  791. range fileThis routine writes the range information for the raster file
  792. <B>name</B> in the current mapset from the <B>range</B> structure.
  793. <P>
  794. A diagnostic message is printed and -1 is returned if there is an error
  795. writing the range file. Otherwise, 0 is returned.
  796. <P>
  797. The range structure must be initialized and updated using the following
  798. routines:
  799. <P>
  800. int G_init_range(struct Range *range) initialize range
  801. structureInitializes the <B>range</B> structure for updates by
  802. <I>G_update_range</I> and <I>G_row_update_range.</I>
  803. <P>
  804. int G_update_range(CELL cat, struct Range *range) update range
  805. structureCompares the <B>cat</B> value with the minimum and maximum
  806. values in the <B>range</B> structure, modifying the range if <B>cat</B>
  807. extends the range.
  808. <P>
  809. int G_row_update_range(CELL *cell, int n, struct Range
  810. *range) update range structureThis routine updates the <B>range</B> data
  811. just like <I>G_update_range</I>, but for <B>n</B> values from the
  812. <B>cell</B> array.
  813. <P>
  814. The range structure is queried using the following routine:
  815. <P>
  816. int G_get_range_min_max(struct Range *range, CELL *min, CELL
  817. *max) get range min and maxThe <B>min</B>inum and <B>max</B>imum CELL
  818. values are extracted from the <B>range</B> structure.
  819. <P>
  820. \section Raster_Histograms Raster Histograms
  821. <P>
  822. The following routines provide a relatively efficient mechanism for computing
  823. and querying a histogram of raster data. They use the <I>Cell_stats</I>
  824. structure to hold the histogram information. The histogram is a count
  825. associated with each unique raster value representing the number of times each
  826. value was inserted into the structure.
  827. <P>
  828. These next two routines are used to manage the Cell_stats structure:
  829. <P>
  830. int G_init_cell_stats(struct Cell_stats *s) initialize cell
  831. statsThis routine, which must be called first, initializes the Cell_stats
  832. structure <B>s.</B>
  833. <P>
  834. int G_free_cell_stats(struct Cell_stats *s) free cell statsThe
  835. memory associated with structure <B>s</B> is freed. This routine may be
  836. called any time after calling<I>G_init_cell_stats.</I>
  837. <P>
  838. This next routine stores values in the histogram:
  839. <P>
  840. int G_update_cell_stats(CELL *data, int n, struct Cell_stats
  841. *s) add data to cell statsThe <B>n</B> CELL values in the <B>data</B>
  842. array are inserted (and counted) in the Cell_stats structure <B>s.</B>
  843. <P>
  844. Once all values are stored, the structure may be queried either randomly (ie.
  845. search for a specific raster value) or sequentially (retrieve all raster
  846. values, in ascending order, and their related count) :
  847. <P>
  848. int G_find_cell_stat(CELL cat, long *count, struct Cell_stats
  849. *s) random query of cell statsThis routine allows a random query of the
  850. Cell_stats structure <B>s.</B> The <B>count</B> associated with the
  851. raster value <B>cat</B> is set. The routine returns 1 if <B>cat</B> was
  852. found in the structure, 0 otherwise.
  853. <P>
  854. Sequential retrieval is accomplished using these next 2 routines:
  855. <P>
  856. int G_rewind_cell_stats(struct Cell_stats *s) reset/rewind cell
  857. statsThe structure <B>s</B> is rewound (i.e., positioned at the first
  858. raster category) so that sorted sequential retrieval can begin.
  859. <P>
  860. int G_next_cell_stat(CELL *cat, long *count, struct Cell_stats
  861. *s) retrieve sorted cell stats Retrieves the next <B>cat,count</B>
  862. combination from the structure <B>s.</B> Returns 0 if there are no more
  863. items, non-zero if there are more.
  864. <P>
  865. For example:
  866. <P>
  867. \verbatim
  868. struct Cell_stats s;
  869. CELL cat;
  870. long count;
  871. .
  872. . /* updating s occurs here */
  873. .
  874. G_rewind_cell_stats(&s);
  875. while (G_next_cell_stat(&cat,&count,&s)
  876. fprintf(stdout, "%ld %ld\n", (long) cat, count);
  877. \endverbatim
  878. <P>
  879. \section GRASS_5_raster_API GRASS 5 raster API [needs to be merged
  880. into above sections]
  881. \subsection The_CELL_Data_Type The CELL Data Type
  882. GRASS integer raster map data is defined to be of type CELL. This data
  883. type is defined in the "gis.h" header file. Programmers must declare
  884. all variables and buffers which will hold raster data or category
  885. codes as type CELL. Under GRASS the CELL data type is declared to be
  886. int, but the programmer should not assume this. What should be assumed
  887. is that CELL is a signed integer type. It may be changed sometime to
  888. short or long. This implies that use of CELL data with routines which
  889. do not know about this data type (e.g., fprintf(stdout, ...), sscanf(),
  890. etc.) must use an intermediate variable of type long. To print a CELL
  891. value, it must be cast to long. For example:
  892. \verbatim
  893. CELL c; /* raster value to be printed */
  894. /* some code to get a value for c */
  895. fprintf(stdout, "%ld\n", (long) c); /* cast c to long to print */
  896. \endverbatim
  897. To read a CELL value, for example from user typed input, it is
  898. necessary to read into a long variable, and then assign it to the CELL
  899. variable. For example (this example does not check for valid inputs,
  900. EOF, etc., which good code must do):
  901. \verbatim
  902. char userbuf[128];
  903. CELL c; long x;
  904. fprintf (stdout, "Which category? "); /* prompt user */
  905. gets(userbuf); /* get user response * /
  906. sscanf (userbuf,"%ld", &x); /* scan category into long variable */
  907. c = (CELL) x; /* assign long value to CELL value */
  908. \endverbatim
  909. Of course, with GRASS library routines that are designed to handle the
  910. CELL type, this problem does not arise. It is only when CELL data must
  911. be used in routines which do not know about the CELL type, that the
  912. values must be cast to or from long.
  913. \subsection 5.0 Changes to <TT>"gis.h"</TT>
  914. <P>
  915. The <TT>"gis.h"</TT> contains 5 new items:
  916. <P>
  917. <PRE>
  918. typedef float FCELL
  919. typedef double DCELL
  920. typedef int RASTER_MAP_TYPE;
  921. #define CELL_TYPE 0
  922. #define FCELL_TYPE 1
  923. #define DCELL_TYPE 2
  924. </PRE>
  925. <P>
  926. Also <TT>"gis.h"</TT> contains the definitions for new structures:
  927. <P>
  928. <PRE>
  929. struct FPReclass;
  930. struct FPRange;
  931. struct Quant;
  932. </PRE>
  933. <P>
  934. Some of the old structures such as
  935. <P>
  936. <PRE>
  937. struct Categories
  938. struct Cell_stats;
  939. struct Range;
  940. struct _Color_Rule_;
  941. struct _Color_Info_;
  942. struct Colors;
  943. </PRE>
  944. <P>
  945. were modified, so it is very important to use functional interface to access
  946. and set elements of these structures instead of accessing elements of the
  947. structures directly. Because some former elements such as for example
  948. <TT>(struct Range range.pmin) </TT> do not exist anymore. It was made sure non
  949. of the former elements have different meaning, so that the programs which do
  950. access the old elements directly either do not compile or work exactly the same
  951. way as prior to change.
  952. <P>
  953. \subsection NULL_value_functions NULL-value functions
  954. <P>
  955. int G_set_null_value(void *rast, int count, RASTER_MAP_TYPE
  956. data_type) Set NULL valueIf the <EM>data_type</EM> is CELL_TYPE, calls
  957. G_set_c_null_value((CELL *) rast, count) ;
  958. <P>
  959. If the <EM>data_type</EM> is FCELL_TYPE, calls G_set_f_null_value((FCELL
  960. *) rast, count) ;
  961. <P>
  962. If the <EM>data_type</EM> is DCELL_TYPE, calls G_set_d_null_value((DCELL
  963. *) rast, count) ;
  964. <P>
  965. int G_set_c_null_value(CELL *cell, int count) Set CELL NULL
  966. valueSet the <EM>count</EM> elements in the <EM>cell</EM> array to the NULL value
  967. (the largest positive integer) .
  968. <P>
  969. int G_set_f_null_value(FCELL *fcell, int count) Set FCELL NULL
  970. valueSet the <EM>count</EM> elements in the <EM>fcell</EM> array to the NULL
  971. value (a bit pattern for a <TT>float</TT> NaN - 32 bits of 1's) .
  972. <P>
  973. int G_set_d_null_value(DCELL *dcell, int count) Set CELL NULL
  974. valueSet the <EM>count</EM> elements in the <EM>dcell</EM> array to the NULL
  975. value - which (a bit pattern for a <TT>double</TT> NaN - 64 bits of 1's) .
  976. <P>
  977. int G_insert_null_values(void *rast, char *flags, int count,
  978. RASTER_MAP_TYPE data_type) Insert NULL valueIf the <EM>data_type</EM> is
  979. CELL_TYPE, calls G_insert_c_null_values ((CELL *) rast, flags, count) ;
  980. <P>
  981. If the <EM>data_type</EM> is FCELL_TYPE, calls G_insert_f_null_values
  982. ((FCELL *) rast, flags, count) ;
  983. <P>
  984. If the <EM>data_type</EM> is DCELL_TYPE, calls G_insert_d_null_values
  985. ((DCELL *) rast, flags, count) ;
  986. <P>
  987. int G_insert_c_null_values(CELL *cell, char *flags, int
  988. count) Insert CELL NULL value For each of the <EM>count</EM> <EM>flags</EM>
  989. which is true(!=0) , set the corresponding <EM>cell</EM> to the NULL value.
  990. <P>
  991. int G_insert_f_null_values(FCELL *fcell, char *flags, int
  992. count) Insert FCELL NULL value For each of the <EM>count</EM> <EM>flags</EM>
  993. which is true(!=0) , set the corresponding <EM>fcell</EM> to the NULL value.
  994. <P>
  995. int G_insert_d_null_values(DCELL *dcell, char *flags, int
  996. count) Insert DCELL NULL value For each for the <EM>count</EM> <EM>flag</EM>
  997. which is true(!=0) , set the corresponding <EM>dcell</EM> to the NULL value.
  998. <P>
  999. int G_is_null_value(void *rast, RASTER_MAP_TYPE data_type) If
  1000. the <EM>data_type</EM> is CELL_TYPE, calls G_is_c_null_value ((CELL *)
  1001. rast) ;
  1002. <P>
  1003. If the <EM>data_type</EM> is FCELL_TYPE, calls G_is_f_null_value ((FCELL
  1004. *) rast) ;
  1005. <P>
  1006. If the <EM>data_type</EM> is DCELL_TYPE, calls G_is_d_null_value ((DCELL
  1007. *) rast) ;
  1008. <P>
  1009. int G_is_c_null_value(CELL *cell) Returns 1 if <EM>cell</EM> is
  1010. NULL, 0 otherwise. This will test if the value <EM>cell</EM> is the largest <TT>int</TT>.
  1011. <P>
  1012. int G_is_f_null_value(FCELL *fcell) Returns 1 if <EM>fcell</EM>
  1013. is NULL, 0 otherwise. This will test if the value <EM>fcell</EM> is a NaN. It
  1014. isn't good enough to test for a particular NaN bit pattern since the machine
  1015. code may change this bit pattern to a different NaN. The test will be
  1016. <P>
  1017. \verbatim
  1018. if(fcell == 0.0) return 0;
  1019. if(fcell > 0.0) return 0;
  1020. if(fcell < 0.0) return 0;
  1021. return 1;
  1022. \endverbatim
  1023. <BR>
  1024. <P>
  1025. or (as suggested by Mark Line)
  1026. <P>
  1027. \verbatim
  1028. return(FCELL != fcell) ;
  1029. \endverbatim
  1030. <P>
  1031. int G_is_d_null_value(DCELL *dcell) Returns 1 if <EM>dcell</EM> is
  1032. NULL, 0 otherwise. This will test if the value <EM>dcell</EM> is a NaN. Same
  1033. test as in <TT>G_is_f_null_value()</TT>.
  1034. <P>
  1035. char * G_allocate_null_buf() Allocate an array of char based on
  1036. the number of columns in the current region.
  1037. <P>
  1038. int G_get_null_value_row (int fd, char *flags, int row) Reads a
  1039. row from NULL value bitmap file for the raster map open for read on <EM>fd</EM>.
  1040. If there is no bitmap file, then this routine simulates the read as follows:
  1041. non-zero values in the raster map correspond to non-NULL; zero values
  1042. correspond to NULL. When MASK exists, masked cells are set to null. <EM>
  1043. flags</EM> is a resulting array of 0's and 1's where 1 corresponds to
  1044. <TT>"no data"</TT> cell.
  1045. <P>
  1046. \subsection Floating_point_and_type_independent_functions Floating-point and type-independent functions
  1047. <P>
  1048. int G_maskfd(void) test for current maskreturns file descriptor
  1049. number if MASK is in use and -1 if no MASK is in use.
  1050. <P>
  1051. int G_raster_map_is_fp(char *name, char *mapset) Returns true(1)
  1052. if raster map <EM>name</EM> in <EM>mapset</EM> is a floating-point dataset;
  1053. false(0) otherwise.
  1054. <P>
  1055. int G_raster_map_type(char *name, char *mapset) Returns the
  1056. storage type for raster map <EM>name</EM> in <EM>mapset</EM>: <TT>CELL_TYPE</TT>
  1057. (int) ; <TT>FCELL_TYPE</TT> (float) ; or <TT>DCELL_TYPE</TT> (double) .
  1058. <P>
  1059. int G_open_raster_new[_uncompressed](char *name,
  1060. RASTER_MAP_TYPE map_type) If map_type == CELL_TYPE, calls
  1061. G_open_map_new[_uncompressed](name) ;
  1062. <P>
  1063. If map_type == FCELL_TYPE, calls G_set_fp_type(FCELL_TYPE) ;
  1064. G_open_fp_map_new[_uncompressed](name) ;
  1065. <P>
  1066. If map_type == DCELL_TYPE, calls G_set_fp_type(DCELL_TYPE) ;
  1067. G_open_fp_map_new[_uncompressed](name) ;
  1068. <P>
  1069. The use of this routine by applications is discouraged since its use would override user
  1070. preferences (what precision to use) .
  1071. <P>
  1072. int G_set_fp_type (RASTER_MAP_TYPE type) This controls the
  1073. storage type for floating-point maps. It affects subsequent calls to
  1074. <TT>G_open_fp_map_new()</TT>. The <EM>type</EM> must be one of <TT>FCELL_TYPE</TT>
  1075. (float) or <TT>DCELL_TYPE</TT> (double) . The use of this routine by
  1076. applications is discouraged since its use would override user preferences.
  1077. <P>
  1078. int G_open_fp_map_new(char *name) Opens a new floating-point
  1079. raster map (in <TT>.tmp</TT>) and returns a file descriptor. The storage type
  1080. (<TT>float</TT> or <TT>double</TT>) is determined by the last call to
  1081. <TT>G_set_fp_type()</TT> or the default (<TT>float</TT> - unless the Unix env
  1082. variable GRASS_FP_DOUBLE is set) .
  1083. <P>
  1084. void * G_allocate_raster_buf(RASTER_MAP_TYPE
  1085. data_type) Allocate an array of CELL, FCELL, or DCELL (depending on <EM>
  1086. data_type</EM>) based on the number of columns in the current region.
  1087. <P>
  1088. CELL * G_allocate_c_raster_buf() Allocate an array of CELL
  1089. based on the number of columns in the current region.
  1090. <P>
  1091. FCELL * G_allocate_f_raster_buf() Allocate an array of FCELL
  1092. based on the number of columns in the current region.
  1093. <P>
  1094. DCELL * G_allocate_d_raster_buf() Allocate an array of DCELL
  1095. based on the number of columns in the current region.
  1096. <P>
  1097. void * G_incr_void_ptr(void *ptr, int size) Advances void
  1098. pointer by n bytes. returns new pointer value. Usefull in raster row
  1099. processing loops, substitutes
  1100. <P>
  1101. \verbatim
  1102. CELL *cell;
  1103. cell += n;
  1104. \endverbatim
  1105. <P>
  1106. Now
  1107. \verbatim
  1108. rast = G_incr_void_ptr(rast, G_raster_size(data_type) )
  1109. \endverbatim
  1110. <P>
  1111. (where rast is void* and data_type is RASTER_MAP_TYPE can be used instead
  1112. of rast++.) very usefull to generalize the row processing - loop (i.e. void *
  1113. buf_ptr += G_raster_size(data_type)
  1114. <P>
  1115. int G_raster_size (RASTER_MAP_TYPE data_type) If <EM>data_type</EM> is CELL_TYPE, returns sizeof(CELL)
  1116. <P>
  1117. If <EM>data_type</EM> is FCELL_TYPE, returns sizeof(FCELL)
  1118. <P>
  1119. If <EM>data_type</EM> is DCELL_TYPE,q returns sizeof(DCELL)
  1120. <P>
  1121. int G_raster_cmp(void *p, *q, RASTER_MAP_TYPE
  1122. data_type) Compares raster vlues p and q. Returns 1 if p &gt; q or only q is
  1123. null value -1 if p &lt; q or only p is null value 0 if p == q or
  1124. p==q==null value
  1125. <P>
  1126. int G_raster_cpy(void *p, void *q, int n, RASTER_MAP_TYPE
  1127. data_type) Copies raster values q into p. If q is null value, sets q to
  1128. null value.
  1129. <P>
  1130. int G_set_raster_value_c(void *p, CELL val, RASTER_MAP_TYPE
  1131. data_type) If G_is_c_null_value(val) is true, sets p to null value.
  1132. Converts CELL val to data_type (type of p) and stores result in p. Used for
  1133. assigning CELL values to raster cells of any type.
  1134. <P>
  1135. int G_set_raster_value_f(void *p, FCELL val, RASTER_MAP_TYPE
  1136. data_type) If G_is_f_null_value(val) is true, sets p to null value.
  1137. Converts FCELL val to data_type (type of p) and stores result in p. Used for
  1138. assigning FCELL values to raster cells of any type.
  1139. <P>
  1140. int G_set_raster_value_d(void *p, DCELL val, RASTER_MAP_TYPE
  1141. data_type) If G_is_d_null_value(val) is true, sets p to null value.
  1142. Converts DCELL val to data_type (type of p) and stores result in p. Used for
  1143. assigning DCELL values to raster cells of any type.
  1144. <P>
  1145. CELL G_get_raster_value_c(void *p, RASTER_MAP_TYPE
  1146. data_type) Retrieves the value of type data_type from pointer p,
  1147. converts it to CELL type and returns the result. If null value is stored in
  1148. p, returns CELL null value. Used for retreiving CELL values from raster cells
  1149. of any type. NOTE: when data_type != CELL_TYPE, no quantization is used,
  1150. only type conversion.
  1151. <P>
  1152. FCELL G_get_raster_value_f(void *p, RASTER_MAP_TYPE
  1153. data_type) Retrieves the value of type data_type from pointer p,
  1154. converts it to FCELL type and returns the result. If null value is stored in
  1155. p, returns FCELL null value. Used for retreiving FCELL values from raster
  1156. cells of any type.
  1157. <P>
  1158. DCELL G_get_raster_value_d(void *p, RASTER_MAP_TYPE
  1159. data_type) Retrieves the value of type data_type from pointer p,
  1160. converts it to DCELL type and returns the result. If null value is stored in
  1161. p, returns DCELL null value. Used for retreiving DCELL values from raster
  1162. cells of any type.
  1163. <P>
  1164. int G_get_raster_row (int fd, void *rast, int row, RASTER_MAP_TYPE
  1165. data_type) If <EM>data_type</EM> is CELL_TYPE, calls
  1166. G_get_c_raster_row(fd,(CELL *) rast, row) ;
  1167. <P>
  1168. If <EM>data_type</EM> is FCELL_TYPE, calls G_get_f_raster_row(fd,(FCELL
  1169. *) rast, row) ;
  1170. <P>
  1171. If <EM>data_type</EM> is DCELL_TYPE, calls G_get_d_raster_row(fd,(DCELL
  1172. *) rast, row) ;
  1173. <P>
  1174. int G_get_raster_row_nomask (int fd, FCELL *fcell, int row,
  1175. RASTER_MAP_TYPE map_type) Same as <TT>G_get_f_raster_row()</TT>
  1176. except no masking occurs.
  1177. <P>
  1178. int G_get_f_raster_row (int fd, FCELL fcell, int row) Read a row
  1179. from the raster map open on <EM>fd</EM> into the <TT>float</TT> array <EM>fcell</EM>
  1180. performing type conversions as necessary based on the actual storage type of
  1181. the map. Masking, resampling into the current region. NULL-values are always
  1182. embedded in <TT>fcell</TT> (<EM>never converted to a value</EM>) .
  1183. <P>
  1184. int G_get_f_raster_row_nomask (int fd, FCELL *fcell, int row)
  1185. Same as <TT>G_get_f_raster_row()</TT> except no masking occurs.
  1186. <P>
  1187. int G_get_d_raster_row (int fd, DCELL *dcell, int row) Same as
  1188. <TT>G_get_f_raster_row()</TT> except that the array <EM>dcell</EM> is <TT>double</TT>.
  1189. <P>
  1190. int G_get_d_raster_row_nomask (int fd, DECLL *dcell, int row)
  1191. Same as <TT>G_get_d_raster_row()</TT> except no masking occurs.
  1192. <P>
  1193. int G_get_c_raster_row (int fd, CELL buf, int row) Reads a row
  1194. of raster data and leaves the NULL values intact. (As opposed to the
  1195. deprecated function <TT>G_get_map_row()</TT> which converts NULL values to
  1196. zero.)
  1197. <P>
  1198. <B>NOTE.</B> When the raster map is old and null file doesn't exist, it is
  1199. assumed that all 0-cells are no-data. When map is floating point, uses quant
  1200. rules set explicitly by G_set_quant_rules or stored in map's quant file to
  1201. convert floats to integers.
  1202. <P>
  1203. int G_get_c_raster_row_nomask (int fd, CELL buf, int row) Same
  1204. as <TT>G_get_c_raster_row()</TT> except no masking occurs.
  1205. <P>
  1206. int G_put_raster_row (int fd, void *rast, RASTER_MAP_TYPE
  1207. data_type) If <EM>data_type</EM> is CELL_TYPE, calls
  1208. G_put_c_raster_row(fd,(CELL *) rast) ;
  1209. <P>
  1210. If <EM>data_type</EM> is FCELL_TYPE, calls G_put_f_raster_row(fd,(FCELL
  1211. *) rast) ;
  1212. <P>
  1213. If <EM>data_type</EM> is DCELL_TYPE, calls G_put_d_raster_row(fd,(DCELL
  1214. *) rast) ;
  1215. <P>
  1216. int G_put_f_raster_row (int fd, FCELL *fcell) Write the next row
  1217. of the raster map open on <EM>fd</EM> from the <TT>float</TT> array <EM>fcell</EM>,
  1218. performing type conversion to the actual storage type of the resultant map.
  1219. Keep track of the range of floating-point values. Also writes the NULL-value
  1220. bitmap from the NULL-values embedded in the <EM>fcell</EM> array.
  1221. <P>
  1222. int G_put_d_raster_row (int fd, DCELL *dcell) Same as <TT>G_put_f_raster_row()</TT>
  1223. except that the array <EM>dcell</EM> is <TT>double</TT>.
  1224. <P>
  1225. int G_put_c_raster_row (int fd, CELL buf) Writes a row of raster
  1226. data and a row of the null-value bitmap, only treating NULL as NULL. (As
  1227. opposed to the deprecated function <TT>G_put_map_row()</TT> which treats zero
  1228. values also as NULL.)
  1229. <P>
  1230. int G_zero_raster_row(void *rast, RASTER_MAP_TYPE
  1231. data_type) Depending on <EM>data_type</EM> zeroes out G_window_cols()
  1232. CELLs, FCELLs, or DCELLs stored in cell buffer.
  1233. <P>
  1234. double G_get_raster_sample(int, struct Cell_head *, struct Categories *,
  1235. double, double, int, INTERP_TYPE)
  1236. extracts a cell value from raster map at given position with
  1237. INTERP_TYPE 0:UNKNOWN; 1: nearest neighbor interpolation;
  1238. 2: bilinear interpolation; 3: cubic interpolation.
  1239. \section Upgrades_to_Raster_Functions Upgrades to Raster Functions (comparing to GRASS 4.x)
  1240. <P>
  1241. These routines will be modified (internally) to work with floating-point and
  1242. NULL-values.
  1243. <P>
  1244. Changes to <TT>GISLIB</TT>:
  1245. <P>
  1246. int G_close_cell() If the map is a new floating point, move the
  1247. <TT>.tmp</TT> file into the <TT>fcell</TT> element, create an empty file in the
  1248. <TT>cell</TT> directory; write the floating-point range file; write a default
  1249. quantization file quantization file is set here to round fp numbers (this is
  1250. a default for now) . create an empty category file, with max cat = max value
  1251. (for backwards compatibility) . Move the <TT>.tmp</TT> NULL-value bitmap file to
  1252. the <TT>cell_misc</TT> directory.
  1253. <P>
  1254. int G_open_cell_old() Arrange for the NULL-value bitmap to be
  1255. read as well as the raster map. If no NULL-value bitmap exists, arrange for
  1256. the production of NULL-values based on zeros in the raster map.
  1257. <P>
  1258. If the map is floating-point, arrange for quantization to integer for <TT>G_get_c_raster_row()</TT>,
  1259. et. al., by reading the quantization rules for
  1260. the map using <TT>G_read_quant()</TT>.
  1261. <P>
  1262. If the programmer wants to read the floating point map using uing quant rules
  1263. other than the ones stored in map's quant file, he/she should call
  1264. G_set_quant_rules() after the call to G_open_cell_old() .
  1265. <P>
  1266. int G_get_map_row() If the map is floating-point, quantize the
  1267. floating-point values to integer using the quantization rules established for
  1268. the map when the map was opened for reading (this quantization is read from
  1269. cell_misc/name/f_quant file, but can be reset after opening raster map by
  1270. G_set_quant_rules() ) .
  1271. <P>
  1272. NULL values are converted to zeros.
  1273. <P>
  1274. <B>This routine is deprecated!!</B>
  1275. <P>
  1276. int G_put_map_row() Zero values are converted to NULLs. Write a
  1277. row of the NULL value bit map.
  1278. <P>
  1279. <B>This routine is deprecated!!</B>
  1280. <P>
  1281. Changes to <TT>D_LIB</TT>:
  1282. <P>
  1283. int Dcell() If the map is a floating-point map, read the map using
  1284. <TT>G_get_d_map_row()</TT> and plot using <TT>D_draw_d_cell()</TT>. If the
  1285. map is an integer map, read the map using <TT>G_get_c_raster_row()</TT> and
  1286. plot using <TT>D_draw_cell()</TT>.
  1287. <P>
  1288. \section Null_no_data NULL (no data) handling
  1289. The <TT>null</TT> file is stored in <TT>cell_misc/name/null file</TT>.
  1290. -2^31 (= 0x80000000 = -2147483648) is the null value
  1291. for the CELL type, so you'll never see that value in a map.
  1292. The FP nulls are the all-ones bit patterns. These corresponds to NaN
  1293. according to the IEEE-754 formats, although it isn't the "default" NaN
  1294. pattern generated by most architectures (which is usually 7fc00000 or
  1295. ffc00000 for float and 7ff8000000000000 or fff8000000000000 for
  1296. double, i.e. an all-ones exponent, the top-bit of the mantissa set,
  1297. and either sign).
  1298. So far as arithmetic is concerned, any value with an all-ones exponent
  1299. and a non-zero mantissa is treated as NaN. But the GRASS
  1300. G_is_[fd]_null_value() functions only consider the all-ones bit
  1301. pattern to be null. I intend to change this in 7.x so that all FP NaN
  1302. values are treated as null. This will mean that code which can
  1303. generate NaNs doesn't have to explicitly convert them to the GRASS
  1304. null value.
  1305. <b>Presence or absence of <TT>null</TT> file:</b>
  1306. For an integer map, any cells which were null will become zero, but
  1307. any zeroes (cells which were previously either null or zero) will be
  1308. treated as nulls (this is for compatibility with GRASS 4.x, which
  1309. didn't have a <TT>null</TT> file, but typically used zero to indicate a null
  1310. value).
  1311. For a floating-point map, any cells which were null will become zero
  1312. (when writing FP data, a null has a zero written to the fcell/<map>
  1313. file, and the corresponding bit is set in the <TT>null</TT>
  1314. file).
  1315. \section Color_Functions Color Functions (new and upgraded)
  1316. \subsection Upgraded_Colors_structures Upgraded Colors structures
  1317. <P>
  1318. \verbatim
  1319. struct _Color_Rule_
  1320. {
  1321. struct
  1322. {
  1323. int version; /* set by read\_colors: -1=old,1=new */
  1324. DCELL shift;
  1325. int invert;
  1326. int is_float; /* defined on floating point raster data? */
  1327. int null_set; /* the colors for null are set? */
  1328. unsigned char null_red, null_grn, null_blu;
  1329. int undef_set; /* the colors for cells not in range are set? */
  1330. unsigned char undef_red, undef_grn, undef_blu;
  1331. struct _Color_Info_ fixed, modular;
  1332. DCELL cmin, cmax;
  1333. };
  1334. \endverbatim
  1335. <P>
  1336. \section New_functions_to_support_colors_for_floating_point New functions to support colors for floating-point
  1337. <P>
  1338. Changes to <TT>GISLIB</TT>:
  1339. <P>
  1340. int G_lookup_raster_colors(void *rast, char *r, char *g, char *b,
  1341. char *set, int n, struct Colors *colors, RASTER_MAP_TYPE cell_type) If
  1342. the <EM>cell_type</EM> is CELL_TYPE, calls G_lookup_colors((CELL *) cell, r,
  1343. g, b, set, n, colors) ;
  1344. <P>
  1345. If the <EM>cell_type</EM> is FCELL_TYPE, calls
  1346. G_lookup_f_raster_colors(FCELL *) cell, r, g, b, set, n, colors) ;
  1347. <P>
  1348. If the <EM>cell_type</EM> is DCELL_TYPE, calls
  1349. G_lookup_d_raster_colors(DCELL *) cell, r, g, b, set, n, colors) ;
  1350. <P>
  1351. int G_lookup_c_raster_colors(CELL *cell, char *r, char *g, char
  1352. *b, char *set, int n, struct Colors *colors) The same as
  1353. G_lookup_colors(cell, r, g, b, set, n, colors) .
  1354. <P>
  1355. int G_lookup_f_raster_colors(FCELL *fcell, char *r, char *g, char
  1356. *b, char *set, int n, struct Colors *colors) Converts the <EM>n</EM>
  1357. floating-point values in the <EM>fcell</EM> array to their <EM>r,g,b</EM> color
  1358. components. Embedded NULL-values are handled properly as well.
  1359. <P>
  1360. int G_lookup_d_raster_colors(DCELL *dcell, char *r, char *g, char
  1361. *b, char *set, int n, struct Colors *colors) Converts the <EM>n</EM>
  1362. floating-point values in the <EM>dcell</EM> array to their <EM>r,g,b</EM> color
  1363. components. Embedded NULL-values are handled properly as well.
  1364. <P>
  1365. int G_add_raster_color_rule(void *v1, int r1, int g1, int b1, void *v2, int r2, int g2, int b2,
  1366. struct Colors *colors, RASTER_MAP_TYPE map_type) If <EM>map_type</EM> is CELL_TYPE, calls G_add_c_raster_color_rule ((CELL
  1367. *) v1, r1, g1, b1,(CELL *) v2, r2, g2, b2, colors) ;
  1368. <P>
  1369. If <EM>map_type</EM> is FCELL_TYPE, calls G_add_f_raster_color_rule
  1370. ((FCELL *) v1, r1, g1, b1,(FCELL *) v2, r2, g2, b2, colors) ;
  1371. <P>
  1372. If <EM>map_type</EM> is DCELL_TYPE, calls G_add_d_raster_color_rule
  1373. ((DCELL *) v1, r1, g1, b1,(DCELL *) v2, r2, g2, b2, colors) ;
  1374. <P>
  1375. int G_add_c_raster_color_rule(CELL *v1, int r1, int g1, int b1,
  1376. CELL *v2, int r2, int g2, int b2, struct Colors *colors) Calls
  1377. G_add_color_rule(*v1, r1, g1, b1, *v2, r2, g2, b2, colors) .
  1378. <P>
  1379. int G_add_f_raster_color_rule(FCELL *v1, int r1, int g1, int b1,
  1380. FCELL *v2, int r2, int g2, int b2, struct Colors *colors) Adds the
  1381. floating-point rule that the range [<EM>v1,v2</EM>] gets a
  1382. linear ramp of colors from [<EM>r1,g1,b1</EM>] to
  1383. [<EM>r2,g2,b2</EM>].
  1384. <P>
  1385. If either <EM>v1</EM> or <EM>v2</EM> is the NULL-value, this call is converted into
  1386. <TT>G_set_null_value_color (r1, g1, b1, colors) </TT>
  1387. <P>
  1388. int G_add_d_raster_color_rule(DCELL *v1, int r1, int g1, int b1,
  1389. DCELL *v2, int r2, int g2, int b2, struct Colors *colors) Adds the
  1390. floating-point rule that the range [<EM>v1,v2</EM>] gets a
  1391. linear ramp of colors from [<EM>r1,g1,b1</EM>] to
  1392. [<EM>r2,g2,b2</EM>].
  1393. <P>
  1394. If either <EM>v1</EM> or <EM>v2</EM> is the NULL-value, this call is converted into
  1395. <TT>G_set_null_value_color (r1, g1, b1, colors) </TT>
  1396. <P>
  1397. int G_get_raster_color(void *v, int *r, int *g, int *b, struct
  1398. Colors *colors, RASTER_MAP_TYPE data_type) Looks up the rgb colors for
  1399. <EM>v</EM> in the color table <EM>colors</EM>
  1400. <P>
  1401. int G_get_c_raster_color(CELL *v, int *r, int *g, int *b, struct
  1402. Colors *colors) Calls G_get_color(*v, r, g, b, colors) .
  1403. <P>
  1404. int G_get_f_raster_color(FCELL *v, int *r, int *g, int *b, struct
  1405. Colors *colors) Looks up the rgb colors for <EM>v</EM> in the color table
  1406. <EM>colors</EM>
  1407. <P>
  1408. int G_get_d_raster_color(DCELL *v, int *r, int *g, int *b, struct
  1409. Colors *colors) Looks up the rgb colors for <EM>v</EM> in the color table
  1410. <EM>colors</EM>
  1411. <P>
  1412. int G_set_raster_color(void *v, int r, int g, int b, struct Colors
  1413. *colors, RASTER_MAP_TYPE data_type) calls <TT>G_add_raster_color_rule (v, r, g, b, v, r, g, r, colors, data_type) ;</TT>
  1414. <P>
  1415. int G_set_c_raster_color(CELL *v, int r, int g, int b, struct
  1416. Colors *colors) Calls G_set_color(*v, r, g, b, colors) .
  1417. <P>
  1418. int G_set_f_raster_color(FCELL *v, int r, int g, int b, struct
  1419. Colors *colors) Inserts a rule that assigns the color <EM>r,g,b</EM> to <EM>v</EM>. It is implemented as:
  1420. <P>
  1421. <TT>G_add_f_raster_color_rule (v, r, g, b, v, r, g, r, colors) ;</TT>
  1422. <P>
  1423. int G_set_d_raster_color(DCELL *v, int r, int g, int b, struct
  1424. Colors *colors) Inserts a rule that assigns the color <EM>r,g,b</EM> to <EM>v</EM>. It is implemented as:
  1425. <P>
  1426. <TT>G_add_d_raster_color_rule (v, r, g, b, v, r, g, r, colors) ;</TT>
  1427. <P>
  1428. int G_mark_colors_as_fp(struct Colors *colors) Sets a flag in
  1429. the <EM>colors</EM> structure that indicates that these colors should only be
  1430. looked up using floating-point raster data (not integer data) .
  1431. <P>
  1432. In particular if this flag is set, the routine <TT>G_get_colors_min_max()</TT> should return
  1433. min=-255&#94;3 and max=255&#94;3.
  1434. <P>
  1435. <P><P>
  1436. <BR>
  1437. <B>These routines are in the <TT>DISPLAYLIB</TT>:</B>
  1438. <P>
  1439. int D_raster_of_type(void *rast, int ncols, int nrows, struct
  1440. Colors *colors, RASTER_MAP_TYPE data_type) If <EM>map_type</EM> is
  1441. CELL_TYPE, calls D_raster((CELL *) rast, ncols, nrows, colors) ;
  1442. <P>
  1443. If <EM>map_type</EM> is FCELL_TYPE, calls D_f_raster((FCELL *) rast, ncols,
  1444. nrows, colors) ;
  1445. <P>
  1446. If <EM>map_type</EM> is DCELL_TYPE, calls D_d_raster((DCELL *) rast, ncols,
  1447. nrows, colors) ;
  1448. <P>
  1449. int D_f_raster(FCELL *fcell, int ncols, int nrows, struct Colors
  1450. *colors) Same functionality as <TT>D_raster()</TT> except that the <EM>fcell</EM>
  1451. array is type <TT>FCELL</TT>. This implies that the floating-point
  1452. interfaces to the <EM>colors</EM> are used by this routine.
  1453. <P>
  1454. int D_d_raster(DCELL *dcell, int ncols, int nrows, struct Colors
  1455. *colors) Same functionality as <TT>D_raster()</TT> except that the <EM>dcell</EM>
  1456. array is type <TT>DCELL</TT>. This implies that the floating-point
  1457. interfaces to the <EM>colors</EM> are used by this routine.
  1458. <P>
  1459. int D_color_of_type(void *value, struct Colors *colors,
  1460. RASTER_MAP_TYPE data_type) If the <EM>data_type</EM> is CELL_TYPE,
  1461. calls D_color((CELL *value, colors) ;
  1462. <P>
  1463. If the <EM>data_type</EM> is FCELL_TYPE, calls D_f_color((FCELL *value,
  1464. colors) ;
  1465. <P>
  1466. If the <EM>data_type</EM> is DCELL_TYPE, calls D_d_color((DCELL *value,
  1467. colors) ;
  1468. <P>
  1469. int D_f_color(FCELL *value, struct Colors *colors) Same
  1470. functionality as <TT>D_color()</TT> except that the <EM>value</EM> is type <TT>FCELL</TT>.
  1471. This implies that the floating-point interfaces to the <EM>colors</EM> are used by this routine.
  1472. <P>
  1473. int D_d_color(DCELL *value, struct Colors *colors) Same
  1474. functionality as <TT>D_color()</TT> except that the <EM>value</EM> is type <TT>DCELL</TT>.
  1475. This implies that the floating-point interfaces to the <EM>colors</EM> are used by this routine.
  1476. <P>
  1477. int D_lookup_raster_colors(void *rast, int *colornum, int n, struct
  1478. Colors *colors, RASTER_MAP_TYPE data_type) If the <EM>data_type</EM> is
  1479. CELL_TYPE, calls D_lookup_c_raster_colors((CELL *) rast, colornum, n,
  1480. colors) ;
  1481. <P>
  1482. If the <EM>data_type</EM> is FCELL_TYPE, calls
  1483. D_lookup_f_raster_colors((FCELL *) rast, colornum, n, colors) ;
  1484. <P>
  1485. If the <EM>data_type</EM> is DCELL_TYPE, calls
  1486. D_lookup_d_raster_colors((DCELL *) rast, colornum, n, colors) ;
  1487. <P>
  1488. int D_lookup_c_raster_colors(CELL *cell, int *colornum, int n,
  1489. struct Colors *colors) Same functionality as <TT>D_lookup_colors()</TT>
  1490. except that the resultant color numbers are placed into a separate <EM>colornum</EM>
  1491. array (which the caller must allocate) .
  1492. <P>
  1493. int D_lookup_f_raster_colors(FCELL *fcell, int *colornum, int n,
  1494. struct Colors *colors) Same functionality as <TT>D_lookup_colors()</TT>
  1495. except that the <EM>fcell</EM> array is type <TT>FCELL</TT> and that the resultant
  1496. color numbers are placed into a separate <EM>colornum</EM> array (which the
  1497. caller must allocate) .
  1498. <P>
  1499. int D_lookup_d_raster_colors(DCELL *dcell, int *colornum, int n,
  1500. struct Colors *colors) Same functionality as <TT>D_lookup_colors()</TT>
  1501. except that the <EM>dcell</EM> array is type <TT>DCELL</TT> and that the resultant
  1502. color numbers are placed into a separate <EM>colornum</EM> array (which the
  1503. caller must allocate) .
  1504. <P>
  1505. int D_draw_cell_of_type(int A_row, DCELL *xarray, struct Colors
  1506. *colors, RASTER_MAP_TYPE map_type) If <EM>map_type</EM> is CELL_TYPE,
  1507. calls D_draw_cell (A_row,(CELL *) xarray, colors) ;
  1508. <P>
  1509. If <EM>map_type</EM> is FCELL_TYPE, calls D_draw_f_cell (A_row,(FCELL *)
  1510. xarray, colors) ;
  1511. <P>
  1512. If <EM>map_type</EM> is DCELL_TYPE, calls D_draw_d_cell (A_row,(DCELL *)
  1513. xarray, colors) ;
  1514. <P>
  1515. int D_draw_f_cell (int A_row, FCELL *xarray, struct Colors
  1516. *colors) Same functionality as <TT>D_draw_cell()</TT> except that the <EM>xarray</EM>
  1517. array is type <TT>FCELL</TT> which implies a call to <TT>D_f_raster()</TT> instead of a call to <TT>D_raster()</TT>.
  1518. <P>
  1519. int D_draw_d_cell (int A_row, DCELL *xarray, struct Colors
  1520. *colors) Same functionality as <TT>D_draw_cell()</TT> except that the <EM>xarray</EM>
  1521. array is type <TT>DCELL</TT> which implies a call to <TT>D_d_raster()</TT> instead of a call to <TT>D_raster()</TT>.
  1522. <P>
  1523. \section New_functions_to_support_a_colors_for_the_NULL_value New functions to support a color for the NULL-value
  1524. <P>
  1525. int G_set_null_value_color (int r, int g, int b, struct Colors
  1526. *colors) Sets the color (in <EM>colors</EM>) for the NULL-value to <EM>r,g,b</EM>.
  1527. <P>
  1528. int G_get_null_value_color (int *r, int *g, int *b, struct Colors
  1529. *colors) Puts the red, green, and blue components of the color for the
  1530. NULL-value into <EM>r,g,b</EM>.
  1531. <P>
  1532. \section New_functions_to_support_a_default_color New functions to support a default color
  1533. <P>
  1534. int G_set_default_color (int r, int g, int b, struct Colors
  1535. *colors) Sets the default color (in <EM>colors</EM>) to <EM>r,g,b</EM>. This is
  1536. the color for values which do not have an explicit rule.
  1537. <P>
  1538. int G_get_default_color (int *r, int *g, int *b, struct Colors
  1539. *colors) Puts the red, green, and blue components of the
  1540. <TT>"default"</TT> color into <EM>r,g,b</EM>.
  1541. <P>
  1542. \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
  1543. <P>
  1544. int G_get_raster_row_colors(int fd, int row, struct Colors *colors,
  1545. unsigned char *red, unsigned char *grn, unsigned char *blu,
  1546. unsigned char *nul) Reads a row of raster data and converts it to red,
  1547. green and blue components according to the <EM>colors</EM> parameter.
  1548. <P>
  1549. This provides a convenient way to treat a raster layer as a color
  1550. image without having to explictly cater for each of <TT>CELL</TT>, <TT> FCELL</TT> and <TT>DCELL</TT> types
  1551. <P>
  1552. \section Upgraded_color_functions Upgraded color functions
  1553. <P>
  1554. int G_read_colors() This routine reads the rules from the color
  1555. file. If the input raster map is is a floating-point map it calls <TT>G_mark_colors_as_fp()</TT>.
  1556. <P>
  1557. int G_write_colors() The rules are written out using
  1558. floating-point format, removing trailing zeros (possibly producing integers) .
  1559. The flag marking the colors as floating-point is <B>not</B> written.
  1560. <P>
  1561. int G_get_colors_min_max() If the color table is marked as
  1562. <TT>"float"</TT>, then return the minimum as -(255&#94;3 * 128) and the maximum
  1563. as (255&#94;3 * 128).
  1564. This is to simulate a very <B>large</B> range so that
  1565. GRASS doesn't attempt to use <EM>colormode float</EM> to allow interactive
  1566. toggling of colors.
  1567. <P>
  1568. int G_lookup_colors() Modified to return a color for NULL-values.
  1569. <P>
  1570. int G_get_color() Modified to return a color for the NULL-value.
  1571. <P>
  1572. \section Changes_to_the_Colors_structure Changes to the <TT>Colors</TT> structure
  1573. <P>
  1574. Modifications to the <TT>Colors</TT> structure to support colors for floating-point data and
  1575. the NULL-value consist of
  1576. <P>
  1577. <UL>
  1578. <LI>the _Color_Rule_ struct was changed to have DCELL value (instead of
  1579. CELL cat) to have the range be floating-point values instead of integer cats.
  1580. </LI>
  1581. <LI>a color for NULL was added
  1582. </LI>
  1583. <LI>the special color for zero was eliminated
  1584. </LI>
  1585. <LI>a default color for values which have no assigned color was added
  1586. </LI>
  1587. <LI>a flag was added to the Colors structure to indicate if either the map
  1588. itself is floating-point (If the map is integer and the floating point
  1589. functions are used to lookup colors, the values are checked to see if they
  1590. are integer, and if they are, the integer mechanism is used)
  1591. </LI>
  1592. <LI>fp_lookup - a lookup table for floating point numbers is added. It
  1593. orders the end points of fp intervals into array with a pointer to a color
  1594. rule for each inteval, and the binary search is then used when looking up
  1595. colors instead of linearly searching through all color rules.
  1596. </LI>
  1597. </UL>
  1598. <P>
  1599. \section Changes_to_the_colr_file Changes to the <TT>colr</TT> file
  1600. <UL>
  1601. <LI>The rules are written out using floating-point format, removing trailing
  1602. zeros (possibly producing integers) . For example, to ramp from red to green
  1603. for the range [1.3,5.0]:
  1604. <PRE>
  1605. 1.3:255:0:0 5:0:255:0
  1606. </PRE>
  1607. </LI>
  1608. <LI>The NULL-value color is written as:
  1609. <PRE>
  1610. nv:red:grn:blu
  1611. </PRE>
  1612. </LI>
  1613. <LI>The default color (for values that don't have an explicit rule) is written
  1614. as:
  1615. <PRE>
  1616. *:red:grn:blu
  1617. </PRE>
  1618. </LI>
  1619. </UL>
  1620. <P>
  1621. \section Range_functions Range functions (new and upgraded)
  1622. \subsection Modified_range_functions Modified range functions
  1623. <P>
  1624. int G_read_range() Old range file (those with 4 numbers) should
  1625. treat zeros in this file as NULL-values. New range files (those with just 2
  1626. numbers) should treat these numbers as real data (zeros are real data in this
  1627. case) .
  1628. <P>
  1629. An empty range file indicates that the min, max are undefined. This is a
  1630. valid case, and the result should be an initialized range struct with no
  1631. defined min/max.
  1632. <P>
  1633. If the range file is missing and the map is a floating-point map, this
  1634. function will create a default range by calling <TT>G_construct_default_range()</TT>.
  1635. <P>
  1636. int G_init_range() Must set a flag in the range structure that indicates that
  1637. no min/max have been defined - probably a <TT>"first"</TT> boolean flag.
  1638. <P>
  1639. int G_update_range() NULL-values must be detected and ignored.
  1640. <P>
  1641. int G_get_range_min_max() If the range structure has no defined min/max
  1642. (first!=0) there will not be a valid range. In this case the min and max returned must
  1643. be the NULL-value.
  1644. <P>
  1645. int G_write_range() This routine only writes 2 numbers (min,max) to the range
  1646. file, instead of the 4 (pmin,pmax,nmin,nmax) previously written. If there is no defined
  1647. min,max, an empty file is written.
  1648. <P>
  1649. \section New_range_functions New range functions
  1650. <P>
  1651. int G_construct_default_range(struct Range *r) Sets the integer
  1652. range <EM>r</EM> to [1,255]
  1653. <P>
  1654. int G_read_raster_range(void *r, char *name, char *mapset,
  1655. RASTER_MAP_TYPEmap_type) If <EM>map_type</EM> is CELL_TYPE, calls
  1656. G_read_range((struct Range *) r, name, mapset) ; otherwise calls
  1657. G_read_fp_range((struct FPRange *) r, name, mapset) ;
  1658. <P>
  1659. int G_read_fp_range(struct FPRange *r, char *name, char
  1660. *mapset) Read the floating point range file <TT>f_range</TT>. This file is
  1661. written in binary using XDR format. If there is no defined min/max in <EM>r</EM>,
  1662. an empty <TT>f_range</TT>file is created.
  1663. <P>
  1664. An empty range file indicates that the min, max are undefined. This is a
  1665. valid case, and the result should be an initialized range struct with no
  1666. defined min/max.
  1667. <P>
  1668. If the range file is missing and the map is a floating-point map, this
  1669. function will create a default range by calling <TT>G_construct_default_range()</TT>.
  1670. <P>
  1671. int G_init_raster_range (FPRange *r, RASTER_MAP_TYPE
  1672. map_type) If <EM>map_type</EM> is CELL_TYPE, calls G_init_range(struct
  1673. Range *) r) ; otherwise calls G_init_fp_range((struct FPRange *) r) ;
  1674. <P>
  1675. int G_init_fp_range (FPRange *r) Must set a flag in the range
  1676. structure that indicates that no min/max have been defined - probably a
  1677. <TT>"first"</TT> boolean flag.
  1678. <P>
  1679. int G_update_f_range (FPRange *r, FCELL *fcell, int n) Updates the
  1680. floating-point range <EM>r</EM> from the <EM>n</EM> <TT>FCELL</TT> values in <EM>fcell</EM>
  1681. NULL-values must be detected and ignored.
  1682. <P>
  1683. int G_update_d_range (FPRange *r, DCELL *dcell, int n) Updates
  1684. the floating-point range <EM>r</EM> from the <EM>n</EM> <TT>DCELL</TT> values in
  1685. <EM>dcell</EM> NULL-values must be detected and ignored.
  1686. <P>
  1687. int G_get_fp_range_min_max (FPRange *r, DCELL *min, DCELL
  1688. *max) Extract the min/max from the range structure <EM>r</EM>.
  1689. <P>
  1690. If the range structure has no defined min/max (first!=0) there will not be a
  1691. valid range. In this case the min and max returned must be the NULL-value.
  1692. <P>
  1693. int G_write_fp_range (FPRange *r) Write the floating point range
  1694. file <TT>f_range</TT>. This file is written in binary using XDR format. If
  1695. there is no defined min/max in <EM>r</EM>, an empty <TT>f_range</TT>file is
  1696. created.
  1697. <P>
  1698. \section New_and_Upgraded_Cell_stats_functions New and Upgraded Cell_stats functions
  1699. <P>
  1700. Modified <TT>Cell_stats</TT> functions to handle NULL-values:
  1701. <P>
  1702. int G_init_cell_stats() Set the count for NULL-values to zero.
  1703. <P>
  1704. int G_update_cell_stats() Look for NULLs and update the
  1705. NULL-value count.
  1706. <P>
  1707. int G_next_cell_stat() Do not return a record for the
  1708. NULL-value
  1709. <P>
  1710. int G_find_cell_stat() Allow finding the count for the
  1711. NULL-value
  1712. <P>
  1713. int G_get_stats_for_null_value(int *count, struct Cell_stats
  1714. *s) Get a number of null values from stats structure. Note: when reporting
  1715. values which appear in a map using G_next_cell_stats() , to get stats for
  1716. null, call G_get_stats_for_null_value() first, since
  1717. G_next_cell_stats() does not report stats for null.
  1718. <P>
  1719. \section New_Quantization_Functions New Quantization Functions
  1720. <P>
  1721. New functions to support quantization of floating-point to integer:
  1722. <P>
  1723. int G_write_quant(char *name, char *mapset, struct Quant
  1724. *q) Writes the <TT>f_quant</TT> file for the raster map <EM>name</EM> from <EM>q</EM>.
  1725. <P>
  1726. if mapset==G_mapset() i.e. the map is in current mapset, then the original
  1727. quant file in cell_misc/map/f_quant is written. Otherwise <EM>q</EM> is
  1728. written into quant2/mapset/name (much like colr2 element) . This results in
  1729. map&#64;mapset being read using quant rules stored in <EM>q</EM> from
  1730. G_mapset() . See G_read_quant() for detailes.
  1731. <P>
  1732. int G_set_quant_rules (int fd, struct Quant *q) Sets quant
  1733. translation rules for raster map opened for reading. fd is a file descriptor
  1734. returned by G_open_cell_old() . After calling this function,
  1735. G_get_c_raster_row() and G_get_map_row() will use rules defined by q
  1736. (instead of using rules defined in map's quant file) to convert floats to
  1737. ints.
  1738. <P>
  1739. int G_read_quant(char *name, char *mapset, struct Quant *q) reads
  1740. quantization rules for <TT>"name"</TT> in <TT>"mapset"</TT> and stores them
  1741. in the quantization structure <TT>"quant"</TT>. If the map is in another
  1742. mapset, first checks for quant2 table for this map in current mapset.
  1743. <P>
  1744. Return codes:
  1745. <P>
  1746. -2 if raster map is of type integer
  1747. <P>
  1748. -1 if (! G__name_is_fully_qualified () )
  1749. <P>
  1750. 0 if quantization file does not exist, or the file is empty or has wrong
  1751. format.
  1752. <P>
  1753. 1 if non-empty quantization file exists.
  1754. <P>
  1755. int G_quant_init(struct Quant *q) Initializes the <EM>q</EM>
  1756. struct.
  1757. <P>
  1758. int G_quant_free(struct Quant *q) Frees any memory allocated in
  1759. <EM>q</EM> and re-initializes <EM>q</EM> by calling <TT>G_quant_init()</TT>.
  1760. <P>
  1761. int G_quant_truncate(struct Quant *q) sets the quant for <EM>q</EM>
  1762. rules to perform simple truncation on floats.
  1763. <P>
  1764. int G_quant_truncate(struct Quant *q) sets the quant for <EM>q</EM>
  1765. rules to perform simple rounding on floats.
  1766. <P>
  1767. int G_quant_organize_fp_lookup(struct Quant *quant) Organizes
  1768. fp_lookup table for faster (logarithmic) lookup time
  1769. G_quant_organize_fp_lookup() creates a list of min and max for each quant
  1770. rule, sorts this list, and stores the pointer to quant rule that should be
  1771. used inbetween any 2 numbers in this list Also it stores extreme points for 2
  1772. infinite rules, if exist After the call to G_quant_organize_fp_lookup()
  1773. instead of linearly searching through list of rules to find a rule to apply,
  1774. quant lookup will perform a binary search to find an interval containing
  1775. floating point value, and then use the rule associated with this interval.
  1776. when the value doesn't fall within any interval, check for the infinite
  1777. rules.
  1778. <P>
  1779. int G_quant_add_rule(struct Quant *q, DCELL dmin, DCELL dmax, CELL
  1780. cmin, CELL cmax) Add the rule that the floating-point range <EM>[dmin,dmin]</EM>
  1781. produces an integer in the range <EM>[cmin,cmax]</EM> by linear interpolation.
  1782. <P>
  1783. Rules that are added later have higher precedence when searching.
  1784. <P>
  1785. If any of of <EM>dmin</EM>, <EM>dmax</EM> <EM>cmin</EM>, or <EM>cmax</EM> is the
  1786. NULL-value, this rule is not added and 0 is returned. Otherwise return 1. if
  1787. the fp_lookup is organized, destroy it.
  1788. <P>
  1789. int G_quant_set_positive_infinite_rule(struct Quant *q, DCELL
  1790. dmax, CELL c) Set the rule that values greater than or equal to <EM>dmax</EM>
  1791. produce the integer <EM>c</EM>. If <EM>dmax</EM> or <EM>c</EM> is the
  1792. NULL-value, return 0 and don't set the rule. Otherwise return 1.
  1793. <P>
  1794. This rule has lower precedence than rules added with <TT>G_quant_add_rule()</TT>.
  1795. <P>
  1796. int G_quant_get_positive_infinite_rule(struct Quant *q, DCELL
  1797. *dmax, CELL *c) Sets <EM>dmax</EM> and <EM>c</EM> to the positive
  1798. <TT>"infinite"</TT> rule in <EM>q</EM> if there is one and returns 1. If there
  1799. is no such rule, it just returns 0. if the fp_lookup is organized, updates
  1800. infinite limits.
  1801. <P>
  1802. int G_quant_set_negative_infinite_rule(struct Quant *q, DCELL
  1803. dmin, CELL c) Set the rule that values less than or equal to <EM>dmin</EM>
  1804. produce the integer <EM>c</EM>. If <EM>dmin</EM> or <EM>c</EM> is the NULL-value,
  1805. return 0 and don't set the rule. Otherwise return 1. if the fp_lookup is
  1806. organized, updates infinite limits.
  1807. <P>
  1808. This rule has lower precedence than rules added with <TT> G_quant_add_rule()</TT>.
  1809. <P>
  1810. int G_quant_get_negative_infinite_rule(struct Quant *q, DCELL
  1811. *dmin, CELL *c) Sets <EM>dmin</EM> and <EM>c</EM> to the negative
  1812. <TT>"infinite"</TT> rule in <EM>q</EM> if there is one and returns 1. If there
  1813. is no such rule, it just returns 0.
  1814. <P>
  1815. int G_quant_get_limits(struct Quant *q, DCELL *dmin, DCELL *dmax,
  1816. CELL *cmin, CELL *cmax) Extracts the minimum and maximum floating-point
  1817. and integer values from all the rules (except the <TT>"infinite"</TT> rules)
  1818. in <EM>q</EM> into <EM>dmin</EM>, <EM>dmax</EM>, <EM>cmin</EM>, and <EM>cmax</EM>. Returns 1
  1819. if there are any explicit rules. If there are no explicit rules, (this
  1820. includes cases when q is set to truncate or round map) , it returns 0 and sets
  1821. <EM>dmin</EM>, <EM>dmax</EM>, <EM>cmin</EM>, and <EM>cmax</EM> to NULL.
  1822. <P>
  1823. int G_quant_nrules(struct Quant *q) Returns the number of rules
  1824. in <EM>q</EM>, excluding the negative and positive <TT>"infinite"</TT> rules.
  1825. <P>
  1826. int G_quant_get_rule(struct Quant *q, int n, DCELL *dmin, DCELL
  1827. *dmax, CELL *cmin, CELL *cmax) Get the <EM>n</EM>th rule from <EM>q</EM>. If 0
  1828. &lt;= <EM>n</EM> &lt; nrules(q) , extract the rule and return 1.
  1829. Otherwise return 0. This function can't be used to get the
  1830. <TT>"infinite"</TT> rules.
  1831. <P>
  1832. The order of the rules returned by increasing <EM>n</EM> is the order in which
  1833. the rules are applied when quantizing a value - the first rule applicable is
  1834. used.
  1835. <P>
  1836. CELL G_quant_get_cell_value(struct Quant *q, DCELL value)
  1837. Returns a CELL category for the floating-point <EM>value</EM> based on the
  1838. quantization rules in <EM>q</EM>. The first rule found that applies is used.
  1839. The rules are searched in the reverse order they are added to <EM>q</EM>. If no
  1840. rule is found, the <EM>value</EM> is first tested against the negative infinite
  1841. rule, and finally against the positive infinite rule. if none of these rules
  1842. apply, the NULL-value is returned.
  1843. <P>
  1844. <B>NOTE.</B> See G_quant_organize_fp_lookup() for details on how the
  1845. values are looked up from fp_lookup table when it is active. (Right now
  1846. fp_lookup is automatically organized during the first call to
  1847. G_quant_get_cell_value()
  1848. <P>
  1849. int G_quant_perform_d(struct Quant *q, DCELL *dcell, CELL *cell,
  1850. int n) Performs a quantization of the <EM>n</EM> <TT>DCELL</TT> values in the
  1851. <EM>dcell</EM> array and puts the results into the <EM>cell</EM> array.
  1852. <P>
  1853. int G_quant_perform_f(struct Quant *q, FCELL *fcell, CELL *cell,
  1854. int n) Performs a quantization of the <EM>n</EM> <TT>FCELL</TT> values in the
  1855. <EM>fcell</EM> array and puts the results into the <EM>cell</EM> array.
  1856. <P>
  1857. These next two functions are convenience functions to allow applications to
  1858. easily create quantization rules other than the defaults:
  1859. <P>
  1860. int G_quantize_fp_map(char *name, CELL cmin, CELL cmax) Writes
  1861. the <TT>f_quant</TT> file for the raster map <EM>name</EM> with one rule. The rule
  1862. is generated using the floating-point range in <TT>f_range</TT> producing the
  1863. integer range [<EM>cmin,cmax</EM>].
  1864. <P>
  1865. int G_quantize_fp_map_range(char *name, DCELL dmin, DCELL dmax,
  1866. CELL cmin, CELL cmax) Writes the <TT>f_quant</TT> file for the raster map
  1867. <EM>name</EM> with one rule. The rule is generated using the floating-point
  1868. range [<EM>dmin,dmax</EM>] and the integer range
  1869. [<EM>min,max</EM>].
  1870. <P>
  1871. This routine differs from the one above in that the application controls the
  1872. floating-point range. For example, r.slope.aspect will use this routine to
  1873. quantize the slope map from [0.0, 90.0] to [0,
  1874. 90] even if the range of slopes is not 0-90. The aspect map would be
  1875. quantized from [0.0, 360.0] to [0, 360].
  1876. <P>
  1877. \section Categories_Labeling_Functions Categories Labeling Functions (new and upgraded)
  1878. \subsection Upgraded_Categories_structure Upgraded Categories structure
  1879. <P>
  1880. All the new programs which are using Categories structure directly have to be
  1881. modified to use API functions to update and retrieve info from Categories
  1882. structure. Both new and old API function can be used, since old functions still
  1883. have exact same functionality (even though internally they are implemented very
  1884. differently) . New function names end with raster_cats() ; old function names
  1885. end with _cats() .
  1886. <BR>
  1887. <P>
  1888. We made sure that all old fields in Categories structure are either missing in
  1889. new Categories structure or have exactly the same meaning. We did it so that
  1890. the modules using Categories structure directly either do not compile with new
  1891. gis library or work exactly the same as bnefore. A programmer might want to
  1892. read the data in a floating point map in a way that each cell value stores
  1893. index of it's category label and data range. The way to do it is to call
  1894. G_set_quant_rules(fd, &amp;pcats-&gt;q) after openning the map.
  1895. <BR>
  1896. <P>
  1897. This is helpful when trying to collect statistics (how many cells of each
  1898. category are in the map. (although there is another new mechanism to collect
  1899. such stats - see G_mark_raster_cats() ) . Another reason to get a category
  1900. index instead of fp values is that this index will be the FID into GRASS-DBMS
  1901. link. Also he can use G_get_ith_raster_cat() to get the category
  1902. information for each cell using this index.
  1903. <BR>
  1904. <P>
  1905. Here is the new Categories structure defined in <TT>"gis.h"</TT>:
  1906. <P>
  1907. \verbatim
  1908. struct Categories
  1909. {
  1910. CELL ncats ; /* total number of categories */
  1911. CELL num ; /* the highest cell values. Only exists
  1912. for backwards compatibility = (CELL)
  1913. max_fp_values in quant rules */
  1914. char *title ; /* name of data layer */
  1915. char *fmt ; /* printf-like format to generate labels */
  1916. float m1 ; /* Multiplication coefficient 1 */
  1917. float a1 ; /* Addition coefficient 1 */
  1918. float m2 ; /* Multiplication coefficient 2 */
  1919. float a2 ; /* Addition coefficient 2 */
  1920. struct Quant q ; /* rules mapping cell values to index in
  1921. list of labels */
  1922. char **labels ; /* array of labels of size num */
  1923. int * marks ; /* was the value with this label was used? */
  1924. int nalloc;
  1925. int last_marked_rule ;
  1926. } ;
  1927. \endverbatim
  1928. <P>
  1929. \section Changes_to_the_cats_file Changes to the <TT>cats</TT> file
  1930. <P>
  1931. The format of explicit label entries is the same for integer maps.
  1932. <PRE>
  1933. cat:description
  1934. </PRE>
  1935. In addition label entries of new format is supported for floating point maps.
  1936. <PRE>
  1937. val:descr (where val is a floating point number)
  1938. </PRE>
  1939. or
  1940. <PRE>
  1941. val1:val2:descr (where val1, val2 is a floating point range)
  1942. </PRE>
  1943. <P>
  1944. Internally the labels are stored for fp ranges of data. However when the cats
  1945. file is written, all the decimal zeros are stripped so that integer values
  1946. appear as integers in the file. Also if values are the same, only 1 value is
  1947. written (i.e. first format) .
  1948. <BR>
  1949. <P>
  1950. This way even though the old cats files will be processed differently
  1951. internally, the user or application programmer will not notice this difference
  1952. as long as the proper api is used and the elements of Categories structure are
  1953. not accessed directly without API calls.
  1954. <P>
  1955. \section Range_functions Range functions (new and upgraded)
  1956. <P>
  1957. \section New_Functions_to_read_write_access_and_modify_Categories_structure New Functions to read/write access and modify Categories structure
  1958. <P>
  1959. int G_read_raster_cats(char *name, *mapset, struct Categories
  1960. *pcats) Is the same as existing G_read_cats()
  1961. <P>
  1962. int G_copy_raster_cats(struct Categories *pcats_to, struct
  1963. Categories*pcats_from) Allocates NEW space for quant rules and labels n
  1964. <EM>pcats_to</EM> and copies all info from <EM>pcats_from</EM> cats to <EM>pcats_to</EM> cats.
  1965. <P>
  1966. returns:
  1967. <P>
  1968. 0 if successful
  1969. <P>
  1970. -1 on fail
  1971. <P>
  1972. char * G_get_raster_cat(void *val, struct Categories *pcats,
  1973. RASTER_MAP_TYPE data_type) given a raster value <EM>val</EM> of type <EM>data_type</EM>
  1974. Returns pointer to a string describing category.
  1975. <P>
  1976. char * G_get_c_raster_cat(CELL *val, struct Categories *pcats)
  1977. given a CELL value <EM>val</EM> Returns pointer to a string describing
  1978. category.
  1979. <P>
  1980. char * G_get_d_raster_cat(DCELL *val, struct Categories
  1981. *pcats) given a DCELL value <EM>val</EM> Returns pointer to a string
  1982. describing category.
  1983. <P>
  1984. char * G_get_f_raster_cat(FCELL *val, struct Categories
  1985. *pcats) given a FCELL value <EM>val</EM> Returns pointer to a string
  1986. describing category.
  1987. <P>
  1988. int G_set_raster_cat(void *rast1, void *rast2, struct Categories
  1989. *pcats, RASTER_MAP_TYPE data_type) Adds the label for range <EM>rast1</EM> through
  1990. <EM>rast2</EM> in category structure <EM>pcats</EM>.
  1991. <P>
  1992. int G_set_c_raster_cat(CELL *rast1, CELL *rast2, struct Categories
  1993. *pcats) Adds the label for range <EM>rast1</EM> through <EM>rast2</EM> in
  1994. category structure <EM>pcats</EM>.
  1995. <P>
  1996. int G_set_f_raster_cat(FCELL *rast1, FCELL *rast2, struct
  1997. Categories *pcats) Adds the label for range <EM>rast1</EM> through <EM>rast2</EM>
  1998. in category structure <EM>pcats</EM>.
  1999. <P>
  2000. int G_set_d_raster_cat(DCELL *rast1, DCELL *rast2, struct
  2001. Categories *pcats) Adds the label for range <EM>rast1</EM> through <EM>rast2</EM>
  2002. in category structure <EM>pcats</EM>.
  2003. <P>
  2004. int * G_number_of_raster_cats (pcats) Returns the number of
  2005. labels. DO NOT use G_number_of_cats() (it returns max cat number)
  2006. <P>
  2007. char * G_get_ith_raster_cat(struct Categories *pcats, int i, void
  2008. *rast1, void *rast2, RASTER_MAP_TYPE data_type) Returns i-th
  2009. description and i-th data range from the list of category descriptions with
  2010. corresponding data ranges. Stores end points of data interval in <EM>rast1</EM>
  2011. and <EM>rast2</EM> (after converting them to <EM>data_type</EM>.
  2012. <P>
  2013. char * G_get_ith_c_raster_cat(struct Categories *pcats, int i,
  2014. CELL *rast1, CELL *rast2) Returns i-th description and i-th data range
  2015. from the list of category descriptions with corresponding data ranges. end
  2016. points of data interval in <EM>rast1</EM> and <EM>rast2</EM>.
  2017. <P>
  2018. char * G_get_ith_f_raster_cat(struct Categories *pcats, int i,
  2019. FCELL *rast1, FCELL *rast2) Returns i-th description and i-th data range
  2020. from the list of category descriptions with corresponding data ranges. end
  2021. points of data interval in <EM>rast1</EM> and <EM>rast2</EM>.
  2022. <P>
  2023. char * G_get_ith_d_raster_cat(struct Categories *pcats, int i,
  2024. DCELL *rast1, DCELL *rast2) Returns i-th description and i-th data range
  2025. from the list of category descriptions with corresponding data ranges. end
  2026. points of data interval in <EM>rast1</EM> and <EM>rast2</EM>.
  2027. <P>
  2028. char * G_get_raster_cats_title(struct Categories
  2029. *pcats) Returns pointer to a string with title.
  2030. <P>
  2031. int G_unmark_raster_cats(struct Categories *pcats) Sets marks
  2032. for all categories to 0. This initializes Categories structure for subsequest
  2033. calls to G_mark_raster_cats (rast_row,...) for each row of data, where
  2034. non-zero mark for i-th label means that some of the cells in rast_row are
  2035. labeled with i-th label and fall into i-th data range.
  2036. <P>
  2037. These marks help determine from the Categories structure which labels were
  2038. used and which weren't.
  2039. <P>
  2040. int G_get_next_marked_raster_cat(struct Categories *pcats, void
  2041. *rast1, void *rast2, long *stats, RASTER_MAP_TYPE data_type) Finds the
  2042. next label and corresponding data range in the list of marked categories. The
  2043. category (label + data range) is marked by G_mark_raster_cats () . End
  2044. points of the data range are converted to <EM>data_type</EM> and returned in
  2045. rast1, rast2. the number of times value from i-th cat. data range appeared so
  2046. far is returned in stats. See G_unmark_raster_cats() ,
  2047. G_rewind_raster_cats() and G_mark_raster_cats () .
  2048. <P>
  2049. int G_get_next_marked_c_raster_cat(struct Categories *pcats, CELL
  2050. *rast1, CELL *rast2, long *stats) Finds the next label and corresponding
  2051. data range in the list of marked categories. The category (label + data
  2052. range) is marked by G_mark_raster_cats () . End points of the data range
  2053. are converted to <EM>data_type</EM> and returned in rast1, rast2. the number of
  2054. times value from i-th cat. data range appeared so far is returned in stats.
  2055. See G_unmark_raster_cats() , G_rewind_raster_cats() and
  2056. G_mark_raster_cats () .
  2057. <P>
  2058. int G_get_next_marked_f_raster_cat(struct Categories *pcats,
  2059. FCELL *rast1, FCELL *rast2, long *stats) Finds the next label and
  2060. corresponding data range in the list of marked categories. The category
  2061. (label + data range) is marked by G_mark_raster_cats () . End points of the
  2062. data range are converted to <EM>data_type</EM> and returned in rast1, rast2.
  2063. the number of times value from i-th cat. data range appeared so far is
  2064. returned in stats. See G_unmark_raster_cats() , G_rewind_raster_cats()
  2065. and G_mark_raster_cats () .
  2066. <P>
  2067. int G_get_next_marked_d_raster_cat(struct Categories *pcats,
  2068. DCELL *rast1, DCELL *rast2, long *stats) Finds the next label and
  2069. corresponding data range in the list of marked categories. The category
  2070. (label + data range) is marked by G_mark_raster_cats () . End points of the
  2071. data range are converted to <EM>data_type</EM> and returned in rast1, rast2.
  2072. the number of times value from i-th cat. data range appeared so far is
  2073. returned in stats. See G_unmark_raster_cats() , G_rewind_raster_cats()
  2074. and G_mark_raster_cats () .
  2075. <P>
  2076. int G_mark_raster_cats(void *rast_row, int ncols, struct
  2077. Categories *pcats, RASTER_MAP_TYPE data_type) Looks up the category
  2078. label for each raster value in the <EM>rast_row</EM> (row of raster cell value)
  2079. and updates the marks for labels found.
  2080. <P>
  2081. NOTE: non-zero mark for i-th label stores the number of of raster cells read
  2082. so far which are labeled with i-th label and fall into i-th data range.
  2083. <P>
  2084. int G_mark_c_raster_cats(CELL *rast_row, int ncols, struct
  2085. Categories *pcats) Looks up the category label for each raster value in
  2086. the <EM>rast_row</EM> and updates the marks for labels found.
  2087. <P>
  2088. NOTE: non-zero mark for i-th label stores the number of of raster cells read
  2089. so far which are labeled with i-th label and fall into i-th data range.
  2090. <P>
  2091. int G_mark_f_raster_cats(FCELL *rast_row, int ncols, struct
  2092. Categories *pcats) Looks up the category label for each raster value in
  2093. the <EM>rast_row</EM> and updates the marks for labels found.
  2094. <P>
  2095. NOTE: non-zero mark for i-th label stores the number of of raster cells read
  2096. so far which are labeled with i-th label and fall into i-th data range.
  2097. <P>
  2098. int G_mark_d_raster_cats(DCELL *rast_row, int ncols, struct
  2099. Categories *pcats) Looks up the category label for each raster value in
  2100. the <EM>rast_row</EM> and updates the marks for labels found.
  2101. <P>
  2102. NOTE: non-zero mark for i-th label stores the number of of raster cells read
  2103. so far which are labeled with i-th label and fall into i-th data range.
  2104. <P>
  2105. int G_rewind_raster_cats(struct Categories *pcats) after call to
  2106. this function G_get_next_marked_raster_cat() returns the first marked
  2107. cat label.
  2108. <P>
  2109. int G_init_raster_cats(char *title, struct Categories
  2110. *pcats) Same as existing G_init_raster_cats() only ncats argument is
  2111. missign. ncats has no meaning in new Categories structure and only stores
  2112. (int) largets data value for backwards compatibility.
  2113. <P>
  2114. int G_set_raster_cats_fmt(char *fmt, float m1, a1, m2, a2, struct
  2115. Categories*pcats) Same as existing G_set_cats_fmt()
  2116. <P>
  2117. int G_set_raster_cats_title(char *title, struct Categories
  2118. *pcats) Same as existing G_set_cats_title()
  2119. <P>
  2120. int G_write_raster_cats(char *name, struct Categories
  2121. *pcats) Same as existing G_write_cats()
  2122. <P>
  2123. int G_free_raster_cats(struct Categories *pcats) Same as
  2124. existing G_free_cats()
  2125. <P>
  2126. \section Library_Functions_that_are_Deprecated Library Functions that are Deprecated
  2127. <P>
  2128. These functions are deprecated, since they imply that the application that uses
  2129. them has not been upgraded to handle NULL-values and should be eliminated from
  2130. GRASS code.
  2131. <P>
  2132. <UL>
  2133. <LI><TT>G_get_map_row()</TT>:
  2134. <P>
  2135. To be replaced by <TT>G_get_c_raster_row()</TT>.
  2136. </LI>
  2137. <LI><TT>G_get_map_row_nomask()</TT>:
  2138. <P>
  2139. To be replaced by <TT>G_get_c_raster_row_nomask()</TT>.
  2140. </LI>
  2141. <LI><TT>G_put_map_row()</TT>:
  2142. <P>
  2143. To be replaced by <TT>G_put_c_raster_row()</TT>.
  2144. </LI>
  2145. </UL>
  2146. <P>
  2147. These functions are deprecated, since they can not be upgraded to support
  2148. NULL-values, and should be eliminated from GRASS code.
  2149. <P>
  2150. <UL>
  2151. <LI><TT>G_open_map_new_random()</TT>
  2152. </LI>
  2153. <LI><TT>G_put_map_row_random()</TT>
  2154. </LI>
  2155. </UL>
  2156. <P>
  2157. <B>Also, no support for random writing of floating-point rasters will be provided.</B>
  2158. <P>
  2159. \section Guidelines_for_upgrading_GRASS_4_x_Modules Guidelines for upgrading GRASS 4.x Modules
  2160. <P>
  2161. <UL>
  2162. <LI>Modules that process raster maps as <EM>continuous</EM> data should read
  2163. raster maps as floating-point. Modules that process raster maps as <EM>nominal</EM> data
  2164. should read raster maps as integer.
  2165. <BR>
  2166. <P>
  2167. <EM>Exception:</EM> Modules that process raster colors or the modules which
  2168. report on raster categories labels should either always read the maps as
  2169. floating-point, or read the maps as integer if the map is integer and
  2170. floating-point if the map is floating-point.
  2171. </LI>
  2172. <LI>The quantization of floating-point to integer should NOT change the color
  2173. table. The color lookup should have its own separate quantization.
  2174. </LI>
  2175. <LI>The quantization of floating-point to integer should NOT change the
  2176. Categories table. The Categories structure should have its own separate
  2177. quantization.
  2178. </LI>
  2179. <LI>Modules that read or write floating-point raster maps should use <TT>double</TT>
  2180. (<TT>DCELL</TT>) arrays instead of <TT>float</TT> (<TT>FCELL</TT>) arrays.
  2181. </LI>
  2182. <LI>Modues should process NULL values in a well defined (consistent) manner.
  2183. Modules that processed zero as the pseudo NULL-value should be changed to use
  2184. the true NULL-value for this and process zero as normal value.
  2185. </LI>
  2186. <LI>Modules should process non-NULL values as normal numbers and not treat
  2187. any particular numbers (e.g. zero) as special.
  2188. </LI>
  2189. </UL>
  2190. <P>
  2191. \section Important_hints_for_upgrades_to_raster_modules Important hints for upgrades to raster modules
  2192. <P>
  2193. In general modules that use <TT>G_get_map_row()</TT>. should use <TT> G_get_c_raster_row()</TT> instead.
  2194. <P>
  2195. Modules that use <TT>G_put_map_row()</TT>. should use <TT> G_put_c_raster_row()</TT> instead.
  2196. */