gis.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /*
  2. * $Id$
  3. *
  4. *****************************************************************************
  5. *
  6. * MODULE: Grass Include Files
  7. * AUTHOR(S): Original author unknown - probably CERL
  8. * Justin Hickey - Thailand - jhickey@hpcc.nectec.or.th
  9. * PURPOSE: This file contains definitions of variables and data types
  10. * for use with most, if not all, Grass programs. This file is
  11. * usually included in every Grass program.
  12. * COPYRIGHT: (C) 2000 by the GRASS Development Team
  13. *
  14. * This program is free software under the GNU General Public
  15. * License (>=v2). Read the file COPYING that comes with GRASS
  16. * for details.
  17. *
  18. *****************************************************************************/
  19. #ifndef GRASS_GIS_H
  20. #define GRASS_GIS_H
  21. /*============================= Include Files ==============================*/
  22. /* System include files */
  23. #include <stdio.h>
  24. #include <stdarg.h>
  25. /* Grass and local include files */
  26. #include <grass/config.h>
  27. #include <grass/datetime.h>
  28. /*=========================== Constants/Defines ============================*/
  29. #if !defined __GNUC__ || __GNUC__ < 2
  30. #undef __attribute__
  31. #define __attribute__(x)
  32. #endif
  33. static const char *GRASS_copyright __attribute__((unused))
  34. = "GRASS GNU GPL licensed Software" ;
  35. /* Define TRUE and FALSE for boolean comparisons */
  36. #ifndef TRUE
  37. #define TRUE 1
  38. #endif
  39. #ifndef FALSE
  40. #define FALSE 0
  41. #endif
  42. #define MAXEDLINES 50
  43. #define RECORD_LEN 80
  44. #define NEWLINE '\n'
  45. #define RECLASS_TABLE 1
  46. #define RECLASS_RULES 2
  47. #define RECLASS_SCALE 3
  48. #define METERS 1
  49. #define FEET 2
  50. #define DEGREES 3
  51. #define CELL_TYPE 0
  52. #define FCELL_TYPE 1
  53. #define DCELL_TYPE 2
  54. #define PROJECTION_XY 0
  55. #define PROJECTION_UTM 1
  56. #define PROJECTION_SP 2
  57. #define PROJECTION_LL 3
  58. #define PROJECTION_OTHER 99
  59. #define PROJECTION_FILE "PROJ_INFO"
  60. #define UNIT_FILE "PROJ_UNITS"
  61. /* define PI and friends */
  62. #undef M_PI
  63. #define M_PI 3.14159265358979323846 /* pi */
  64. #undef M_PI_2
  65. #define M_PI_2 1.57079632679489661923 /* pi/2 */
  66. #undef M_PI_4
  67. #define M_PI_4 0.78539816339744830962 /* pi/4 */
  68. /* epsilon (IEEE: 2.220446e-16) */
  69. #define GRASS_EPSILON 1.0e-15
  70. /* Location of envariment variables */
  71. #define G_VAR_GISRC 0
  72. #define G_VAR_MAPSET 1
  73. /* Where to find/store variables */
  74. #define G_GISRC_MODE_FILE 0 /* files */
  75. #define G_GISRC_MODE_MEMORY 1 /* memory only */
  76. /* for G_parser() */
  77. #define TYPE_INTEGER 1
  78. #define TYPE_DOUBLE 2
  79. #define TYPE_STRING 3
  80. #define YES 1
  81. #define NO 0
  82. #define GISPROMPT_COLOR "color,grass,color"
  83. /* File/directory name lengths */
  84. #define GNAME_MAX 256
  85. #define GMAPSET_MAX 256
  86. #define GPATH_MAX 4096
  87. /* Macros for type size independent integers */
  88. /* Use these for portability to ensure integers are truly 32bit */
  89. /* and are handled in a uniform manner */
  90. /* Convert integer to 4 bytes - little endian */
  91. #define serialize_int32_le(buf, x) do { \
  92. (buf)[0] = ((x) >> 0) & 0xFF; \
  93. (buf)[1] = ((x) >> 8) & 0xFF; \
  94. (buf)[2] = ((x) >> 16) & 0xFF; \
  95. (buf)[3] = ((x) >> 24) & 0xFF; \
  96. } while(0)
  97. /* Convert 4 bytes to an integer - little endian */
  98. #define deserialize_int32_le(buf) (((buf)[0] << 0) | \
  99. ((buf)[1] << 8) | \
  100. ((buf)[2] << 16) | \
  101. ((buf)[3] << 24))
  102. /* Convert integer to 4 bytes - big endian */
  103. #define serialize_int32_be(buf, x) do { \
  104. (buf)[0] = ((x) >> 24) & 0xFF; \
  105. (buf)[1] = ((x) >> 16) & 0xFF; \
  106. (buf)[2] = ((x) >> 8) & 0xFF; \
  107. (buf)[3] = ((x) >> 0) & 0xFF; \
  108. } while(0)
  109. /* Convert 4 bytes to an integer - big endian */
  110. #define deserialize_int32_be(buf) (((buf)[0] << 24) | \
  111. ((buf)[1] << 16) | \
  112. ((buf)[2] << 8) | \
  113. ((buf)[3] << 0))
  114. /* Cross-platform Directory Separator Character and null device stuff */
  115. #define GRASS_DIRSEP '/'
  116. #ifdef __MINGW32__
  117. # define HOST_DIRSEP '\\'
  118. # define G_DEV_NULL 'NUL:'
  119. #else
  120. # define HOST_DIRSEP '/'
  121. # define G_DEV_NULL '/dev/null'
  122. #endif
  123. /**/
  124. typedef enum {
  125. G_OPT_WHERE, /* SQL where conditions */
  126. G_OPT_TABLE, /* table name */
  127. G_OPT_DRIVER, /* driver name */
  128. G_OPT_DATABASE, /* database name */
  129. G_OPT_COLUMN, /* one attr column */
  130. G_OPT_COLUMNS, /* one or more attr columns */
  131. G_OPT_I_GROUP, /* old input imagery group */
  132. G_OPT_I_SUBGROUP, /* old input imagery subgroup */
  133. G_OPT_R_INPUT, /* old input raster map */
  134. G_OPT_R_INPUTS, /* old input raster maps */
  135. G_OPT_R_OUTPUT, /* new output raster map */
  136. G_OPT_R_MAP, /* old input raster map */
  137. G_OPT_R_MAPS, /* old input rasters map */
  138. G_OPT_R_BASE, /* old input base raster map */
  139. G_OPT_R_COVER, /* old input cover raster map */
  140. G_OPT_R_ELEV, /* old input elevation raster map */
  141. G_OPT_R_ELEVS, /* old input elevation raster maps */
  142. G_OPT_R3_INPUT, /* old input raster3d map */
  143. G_OPT_R3_INPUTS, /* old input raster3d maps */
  144. G_OPT_R3_OUTPUT, /* new output raster3d map */
  145. G_OPT_R3_MAP, /* old input raster3d map */
  146. G_OPT_R3_MAPS, /* old input raster3d maps */
  147. G_OPT_V_INPUT, /* old input vector map */
  148. G_OPT_V_INPUTS, /* old input vector maps */
  149. G_OPT_V_OUTPUT, /* new output vector map */
  150. G_OPT_V_MAP, /* old input vector map */
  151. G_OPT_V_MAPS, /* old input vector maps */
  152. G_OPT_V_TYPE, /* primitive type */
  153. G_OPT_V_FIELD, /* layer number (layers used to be called fields) */
  154. G_OPT_V_CAT, /* one category */
  155. G_OPT_V_CATS, /* more categories */
  156. G_OPT_F_INPUT, /* old input file */
  157. G_OPT_F_OUTPUT, /* new output file */
  158. G_OPT_F_SEP, /* data field separator */
  159. G_OPT_C_FG, /* foreground color */
  160. G_OPT_C_BG /* background color */
  161. } STD_OPT;
  162. /* Message format */
  163. #define G_INFO_FORMAT_STANDARD 0 /* GRASS_MESSAGE_FORMAT=standard or not defined */
  164. #define G_INFO_FORMAT_GUI 1 /* GRASS_MESSAGE_FORMAT=gui */
  165. #define G_INFO_FORMAT_SILENT 2 /* GRASS_MESSAGE_FORMAT=silent */
  166. /* Icon types */
  167. #define G_ICON_CROSS 0
  168. #define G_ICON_BOX 1
  169. #define G_ICON_ARROW 2
  170. /* default colors */
  171. #define DEFAULT_FG_COLOR "black"
  172. #define DEFAULT_BG_COLOR "white"
  173. /* for G_get_raster_sample(), INTERP_TYPE */
  174. #define UNKNOWN 0
  175. #define NEAREST 1 /* nearest neighbor interpolation */
  176. #define BILINEAR 2 /* bilinear interpolation */
  177. #define CUBIC 3 /* cubic interpolation */
  178. /* for raster maps */
  179. #define GR_FATAL_EXIT 0
  180. #define GR_FATAL_PRINT 1
  181. #define GR_FATAL_RETURN 2
  182. /* Element types */
  183. enum { /* Dir */
  184. G_ELEMENT_RASTER = 1, /* cell */
  185. G_ELEMENT_RASTER3D = 2, /* 3dcell */
  186. G_ELEMENT_VECTOR = 3, /* vector */
  187. G_ELEMENT_OLDVECTOR = 4, /* GRASS < 5.7 vector */
  188. G_ELEMENT_ASCIIVECTOR = 5, /* ASCII vector */
  189. G_ELEMENT_ICON = 6, /* icon */
  190. G_ELEMENT_LABEL = 7, /* labels */
  191. G_ELEMENT_SITE = 8, /* sites */
  192. G_ELEMENT_REGION = 9, /* region */
  193. G_ELEMENT_REGION3D = 10, /* 3dregion */
  194. G_ELEMENT_GROUP = 11, /* group */
  195. G_ELEMENT_3DVIEW = 12 /* 3dview */
  196. };
  197. /*=========================== Typedefs/Structures ==========================*/
  198. typedef int CELL;
  199. typedef double DCELL;
  200. typedef float FCELL;
  201. extern CELL CELL_NODATA;
  202. typedef int RASTER_MAP_TYPE;
  203. /* for G_get_raster_sample() */
  204. typedef int INTERP_TYPE;
  205. struct Cell_head
  206. {
  207. int format; /* max numer of bytes per cell minus 1 */
  208. int compressed; /* 0 = uncompressed, 1 = compressed, -1 pre 3.0 */
  209. int rows; /* number of rows in the data 2D */
  210. int rows3; /* number of rows in the data 3D */
  211. int cols; /* number of columns in the data 2D */
  212. int cols3; /* number of columns in the data 3D */
  213. int depths; /* number of depths in data */
  214. int proj; /* Projection (see #defines above) */
  215. int zone; /* Projection zone */
  216. double ew_res; /* East to West cell size 2D */
  217. double ew_res3; /* East to West cell size 3D */
  218. double ns_res; /* North to South cell size 2D */
  219. double ns_res3; /* North to South cell size 3D */
  220. double tb_res; /* Top to Bottom cell size */
  221. double north; /* coordinates of layer */
  222. double south;
  223. double east;
  224. double west;
  225. double top;
  226. double bottom;
  227. };
  228. struct _Color_Rule_
  229. {
  230. struct
  231. {
  232. DCELL value;
  233. unsigned char red;
  234. unsigned char grn;
  235. unsigned char blu;
  236. } low, high;
  237. struct _Color_Rule_ *next;
  238. struct _Color_Rule_ *prev;
  239. };
  240. struct _Color_Info_
  241. {
  242. struct _Color_Rule_ *rules;
  243. int n_rules;
  244. struct
  245. {
  246. unsigned char *red;
  247. unsigned char *grn;
  248. unsigned char *blu;
  249. unsigned char *set;
  250. int nalloc;
  251. int active;
  252. } lookup;
  253. struct
  254. {
  255. DCELL *vals;
  256. /* pointers to color rules corresponding to the intervals btwn vals */
  257. struct _Color_Rule_ **rules;
  258. int nalloc;
  259. int active;
  260. } fp_lookup;
  261. DCELL min, max;
  262. };
  263. struct Colors
  264. {
  265. int version; /* set by read_colors: -1=old,1=new */
  266. DCELL shift;
  267. int invert;
  268. int is_float; /* defined on floating point raster data? */
  269. int null_set; /* the colors for null are set? */
  270. unsigned char null_red;
  271. unsigned char null_grn;
  272. unsigned char null_blu;
  273. int undef_set; /* the colors for cells not in range are set? */
  274. unsigned char undef_red;
  275. unsigned char undef_grn;
  276. unsigned char undef_blu;
  277. struct _Color_Info_ fixed;
  278. struct _Color_Info_ modular;
  279. DCELL cmin;
  280. DCELL cmax;
  281. };
  282. typedef struct
  283. {
  284. unsigned char r, g, b, a; /* red, green, blue, and alpha */
  285. } RGBA_Color ;
  286. typedef RGBA_Color RGB_Color;
  287. /* RGBA_Color alpha presets */
  288. #define RGBA_COLOR_OPAQUE 255
  289. #define RGBA_COLOR_TRANSPARENT 0
  290. #define RGBA_COLOR_NONE 0
  291. struct Reclass
  292. {
  293. char *name; /* name of raster map being reclassed */
  294. char *mapset; /* mapset in which "name" is found */
  295. int type; /* type of reclass */
  296. int num; /* size of reclass table */
  297. CELL min; /* table min */
  298. CELL max; /* table max */
  299. CELL *table; /* reclass table */
  300. } ;
  301. struct FPReclass_table
  302. {
  303. DCELL dLow; /* domain low */
  304. DCELL dHigh; /* domain high */
  305. DCELL rLow; /* range low */
  306. DCELL rHigh; /* range high */
  307. };
  308. /* reclass structure from double to double used by r.recode to reclass */
  309. /* between types: int to double, float to int,... */
  310. struct FPReclass
  311. {
  312. int defaultDRuleSet; /* 1 if default domain rule set */
  313. int defaultRRuleSet; /* 1 if default range rule set */
  314. int infiniteLeftSet; /* 1 if negative infinite interval rule exists */
  315. int infiniteRightSet; /* 1 if positive infinite interval rule exists */
  316. int rRangeSet; /* 1 if range range (i.e. interval) is set */
  317. int maxNofRules;
  318. int nofRules;
  319. DCELL defaultDMin; /* default domain minimum value */
  320. DCELL defaultDMax; /* default domain maximum value */
  321. DCELL defaultRMin; /* default range minimum value */
  322. DCELL defaultRMax; /* default range maximum value */
  323. DCELL infiniteDLeft; /* neg infinite rule */
  324. DCELL infiniteDRight; /* neg infinite rule */
  325. DCELL infiniteRLeft; /* pos infinite rule */
  326. DCELL infiniteRRight; /* pos infinite rule */
  327. DCELL dMin; /* minimum domain values in rules */
  328. DCELL dMax; /* maximum domain values in rules */
  329. DCELL rMin; /* minimum range values in rules */
  330. DCELL rMax; /* maximum range values in rules */
  331. struct FPReclass_table *table;
  332. };
  333. struct Quant_table
  334. {
  335. DCELL dLow;
  336. DCELL dHigh;
  337. CELL cLow;
  338. CELL cHigh;
  339. };
  340. struct Quant
  341. {
  342. int truncate_only;
  343. int round_only;
  344. int defaultDRuleSet;
  345. int defaultCRuleSet;
  346. int infiniteLeftSet;
  347. int infiniteRightSet;
  348. int cRangeSet;
  349. int maxNofRules;
  350. int nofRules;
  351. DCELL defaultDMin;
  352. DCELL defaultDMax;
  353. CELL defaultCMin;
  354. CELL defaultCMax;
  355. DCELL infiniteDLeft;
  356. DCELL infiniteDRight;
  357. CELL infiniteCLeft;
  358. CELL infiniteCRight;
  359. DCELL dMin;
  360. DCELL dMax;
  361. CELL cMin;
  362. CELL cMax;
  363. struct Quant_table *table;
  364. struct
  365. {
  366. DCELL *vals;
  367. /* pointers to quant rules corresponding to the intervals btwn vals */
  368. struct Quant_table **rules;
  369. int nalloc;
  370. int active;
  371. DCELL inf_dmin;
  372. DCELL inf_dmax;
  373. CELL inf_min;
  374. CELL inf_max;
  375. /* all values smaller than inf_dmin become inf_min */
  376. /* all values larger than inf_dmax become inf_max */
  377. /* inf_min and/or inf_max can be NULL if there are no inf rules */
  378. } fp_lookup;
  379. };
  380. struct Categories
  381. {
  382. CELL ncats; /* total number of categories */
  383. CELL num; /* the highest cell values. Only exists
  384. for backwards compatibility = (CELL)
  385. max_fp_values in quant rules */
  386. char *title; /* name of data layer */
  387. char *fmt; /* printf-like format to generate labels */
  388. float m1; /* Multiplication coefficient 1 */
  389. float a1; /* Addition coefficient 1 */
  390. float m2; /* Multiplication coefficient 2 */
  391. float a2; /* Addition coefficient 2 */
  392. struct Quant q; /* rules mapping cell values to index in
  393. list of labels */
  394. char **labels; /* array of labels of size num */
  395. int *marks; /* was the value with this label was used? */
  396. int nalloc;
  397. int last_marked_rule;
  398. /* NOTE: to get a rule corresponfing to cats.labels[i], use */
  399. /* G_get_ith_c/f/d_raster_cat (pcats, i, val1, val2) */
  400. /* it calls */
  401. /* G_quant_get_ith_rule(&cats->q, i, val1, val2, &index, &index); */
  402. /* and idex ==i, because rule is added at the same time as a */
  403. /* label, and quant rules are never reordered. Olga apr,95 */
  404. };
  405. struct History
  406. {
  407. char mapid[RECORD_LEN];
  408. char title[RECORD_LEN];
  409. char mapset[RECORD_LEN];
  410. char creator[RECORD_LEN];
  411. char maptype[RECORD_LEN];
  412. char datsrc_1[RECORD_LEN];
  413. char datsrc_2[RECORD_LEN];
  414. char keywrd[RECORD_LEN];
  415. int edlinecnt;
  416. char edhist[MAXEDLINES][RECORD_LEN];
  417. };
  418. struct Cell_stats
  419. {
  420. struct Cell_stats_node
  421. {
  422. int idx;
  423. long *count;
  424. int left;
  425. int right;
  426. } *node ; /* tree of values */
  427. int tlen ; /* allocated tree size */
  428. int N; /* number of actual nodes in tree */
  429. int curp;
  430. long null_data_count;
  431. int curoffset;
  432. };
  433. struct Histogram
  434. {
  435. int num;
  436. struct Histogram_list
  437. {
  438. CELL cat;
  439. long count;
  440. } *list;
  441. };
  442. struct Range
  443. {
  444. CELL min;
  445. CELL max;
  446. int first_time; /* whether or not range was updated */
  447. };
  448. struct FPRange
  449. {
  450. DCELL min;
  451. DCELL max;
  452. int first_time; /* whether or not range was updated */
  453. };
  454. /*
  455. ** Structure for I/O of 3dview files (view.c)
  456. */
  457. struct G_3dview
  458. {
  459. char pgm_id[40]; /* user-provided identifier */
  460. float from_to[2][3]; /* eye position & lookat position */
  461. float fov; /* field of view */
  462. float twist; /* right_hand rotation about from_to */
  463. float exag; /* terrain elevation exageration */
  464. int mesh_freq; /* cells per grid line */
  465. int poly_freq; /* cells per polygon */
  466. int display_type; /* 1 for mesh, 2 for poly, 3 for both */
  467. int lightson; /* boolean */
  468. int dozero; /* boolean */
  469. int colorgrid; /* boolean */
  470. int shading; /* boolean */
  471. int fringe; /* boolean */
  472. int surfonly; /* boolean */
  473. int doavg; /* boolean */
  474. char grid_col[40]; /* colors */
  475. char bg_col[40]; /* colors */
  476. char other_col[40]; /* colors */
  477. float lightpos[4]; /* east, north, height, 1.0 for local 0.0 infin */
  478. float lightcol[3]; /* values between 0.0 to 1.0 for red, grn, blu */
  479. float ambient;
  480. float shine;
  481. struct Cell_head vwin;
  482. };
  483. struct Key_Value
  484. {
  485. int nitems;
  486. int nalloc;
  487. char **key;
  488. char **value;
  489. };
  490. struct Option /* Structure that stores option info */
  491. {
  492. char *key; /* Key word used on command line */
  493. int type; /* Option type */
  494. int required; /* REQUIRED or OPTIONAL */
  495. int multiple; /* Multiple entries OK */
  496. char *options; /* Approved values or range or NULL */
  497. char **opts; /* NULL or NULL terminated array of parsed options */
  498. char *key_desc; /* one word describing the key */
  499. char *label; /* Optional short label, used in GUI as item label */
  500. char *description; /* String describing option */
  501. char *descriptions; /* ';' separated pairs of option and option descriptions */
  502. /* For example: (with ->options = "break,rmdupl")
  503. * "break;break lines on intersections;"
  504. * "rmdupl;remove duplicates"
  505. */
  506. char **descs; /* parsed descriptions, array of either NULL or string */
  507. /* in the same order as options */
  508. char *answer; /* Option answer */
  509. char *def; /* Where original answer gets saved */
  510. char **answers; /* Option answers (for multiple=YES)*/
  511. struct Option *next_opt; /* Pointer to next option struct */
  512. char *gisprompt; /* Interactive prompt guidance */
  513. char *guisection; /* GUI Layout guidance: ';' delimited heirarchical tree position */
  514. int (*checker)(); /* Routine to check answer or NULL */
  515. int count;
  516. };
  517. struct Flag /* Structure that stores flag info */
  518. {
  519. char key; /* Key char used on command line */
  520. char answer; /* Stores flag state: 0/1 */
  521. char *label; /* Optional short label, used in GUI as item label */
  522. char *description; /* String describing flag meaning */
  523. char *guisection; /* GUI Layout guidance: ';' delimited heirarchical tree position */
  524. struct Flag *next_flag; /* Pointer to next flag struct */
  525. };
  526. struct GModule /* Structure that stores module info */
  527. {
  528. char *label; /* Optional short description for GUI */
  529. char *description; /* String describing module */
  530. char *keywords; /* Keywords describing module */
  531. /* further items are possible: author(s), version */
  532. int overwrite; /* overwrite old files */
  533. int verbose; /* print all informations about progress and so on */
  534. };
  535. struct TimeStamp
  536. {
  537. DateTime dt[2]; /* two datetimes */
  538. int count;
  539. };
  540. /*============================== Prototypes ================================*/
  541. /* Since there are so many prototypes for the gis library they are stored */
  542. /* in the file gisdefs.h */
  543. #include <grass/gisdefs.h>
  544. #endif /* GRASS_GIS_H */