gis.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /*
  2. *****************************************************************************
  3. *
  4. * MODULE: Grass Include Files
  5. * AUTHOR(S): Original author unknown - probably CERL
  6. * Justin Hickey - Thailand - jhickey@hpcc.nectec.or.th
  7. * PURPOSE: This file contains definitions of variables and data types
  8. * for use with most, if not all, Grass programs. This file is
  9. * usually included in every Grass program.
  10. * COPYRIGHT: (C) 2000 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. *****************************************************************************/
  17. #ifndef GRASS_GIS_H
  18. #define GRASS_GIS_H
  19. /*============================= Include Files ==============================*/
  20. /* System include files */
  21. #include <stdio.h>
  22. #include <stdarg.h>
  23. /* Grass and local include files */
  24. #include <grass/config.h>
  25. #include <grass/datetime.h>
  26. /*=========================== Constants/Defines ============================*/
  27. #if !defined __GNUC__ || __GNUC__ < 2
  28. #undef __attribute__
  29. #define __attribute__(x)
  30. #endif
  31. static const char *GRASS_copyright __attribute__ ((unused))
  32. = "GRASS GNU GPL licensed Software";
  33. #define GIS_H_VERSION "$Revision$"
  34. #define G_gisinit(pgm) G__gisinit(GIS_H_VERSION, (pgm))
  35. #define G_no_gisinit() G__no_gisinit(GIS_H_VERSION)
  36. /* Define TRUE and FALSE for boolean comparisons */
  37. #ifndef TRUE
  38. #define TRUE 1
  39. #endif
  40. #ifndef FALSE
  41. #define FALSE 0
  42. #endif
  43. #define MAXEDLINES 50
  44. #define RECORD_LEN 80
  45. #define NEWLINE '\n'
  46. #define RECLASS_TABLE 1
  47. #define RECLASS_RULES 2
  48. #define RECLASS_SCALE 3
  49. #define METERS 1
  50. #define FEET 2
  51. #define DEGREES 3
  52. #define CELL_TYPE 0
  53. #define FCELL_TYPE 1
  54. #define DCELL_TYPE 2
  55. #define PROJECTION_XY 0
  56. #define PROJECTION_UTM 1
  57. #define PROJECTION_SP 2
  58. #define PROJECTION_LL 3
  59. #define PROJECTION_OTHER 99
  60. #define PROJECTION_FILE "PROJ_INFO"
  61. #define UNIT_FILE "PROJ_UNITS"
  62. /* define PI and friends */
  63. #undef M_PI
  64. #define M_PI 3.14159265358979323846 /* pi */
  65. #undef M_PI_2
  66. #define M_PI_2 1.57079632679489661923 /* pi/2 */
  67. #undef M_PI_4
  68. #define M_PI_4 0.78539816339744830962 /* pi/4 */
  69. /* epsilon (IEEE: 2.220446e-16) */
  70. #define GRASS_EPSILON 1.0e-15
  71. /* Location of envariment variables */
  72. #define G_VAR_GISRC 0
  73. #define G_VAR_MAPSET 1
  74. /* Where to find/store variables */
  75. #define G_GISRC_MODE_FILE 0 /* files */
  76. #define G_GISRC_MODE_MEMORY 1 /* memory only */
  77. /* for G_parser() */
  78. #define TYPE_INTEGER 1
  79. #define TYPE_DOUBLE 2
  80. #define TYPE_STRING 3
  81. #define YES 1
  82. #define NO 0
  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. /**/ typedef enum
  124. {
  125. G_OPT_DB_WHERE, /* SQL where conditions */
  126. G_OPT_DB_TABLE, /* table name */
  127. G_OPT_DB_DRIVER, /* driver name */
  128. G_OPT_DB_DATABASE, /* database name */
  129. G_OPT_DB_COLUMN, /* one attr column */
  130. G_OPT_DB_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
  184. { /* Dir */
  185. G_ELEMENT_RASTER = 1, /* cell */
  186. G_ELEMENT_RASTER3D = 2, /* 3dcell */
  187. G_ELEMENT_VECTOR = 3, /* vector */
  188. G_ELEMENT_OLDVECTOR = 4, /* GRASS < 5.7 vector */
  189. G_ELEMENT_ASCIIVECTOR = 5, /* ASCII vector */
  190. G_ELEMENT_ICON = 6, /* icon */
  191. G_ELEMENT_LABEL = 7, /* labels */
  192. G_ELEMENT_SITE = 8, /* sites */
  193. G_ELEMENT_REGION = 9, /* region */
  194. G_ELEMENT_REGION3D = 10, /* 3dregion */
  195. G_ELEMENT_GROUP = 11, /* group */
  196. G_ELEMENT_3DVIEW = 12 /* 3dview */
  197. };
  198. /*=========================== Typedefs/Structures ==========================*/
  199. typedef int CELL;
  200. typedef double DCELL;
  201. typedef float FCELL;
  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_Value_
  229. {
  230. DCELL value;
  231. unsigned char red;
  232. unsigned char grn;
  233. unsigned char blu;
  234. };
  235. struct _Color_Rule_
  236. {
  237. struct _Color_Value_ low, high;
  238. struct _Color_Rule_ *next;
  239. struct _Color_Rule_ *prev;
  240. };
  241. struct _Color_Info_
  242. {
  243. struct _Color_Rule_ *rules;
  244. int n_rules;
  245. struct
  246. {
  247. unsigned char *red;
  248. unsigned char *grn;
  249. unsigned char *blu;
  250. unsigned char *set;
  251. int nalloc;
  252. int active;
  253. } lookup;
  254. struct
  255. {
  256. DCELL *vals;
  257. /* pointers to color rules corresponding to the intervals btwn vals */
  258. struct _Color_Rule_ **rules;
  259. int nalloc;
  260. int active;
  261. } fp_lookup;
  262. DCELL min, max;
  263. };
  264. struct Colors
  265. {
  266. int version; /* set by read_colors: -1=old,1=new */
  267. DCELL shift;
  268. int invert;
  269. int is_float; /* defined on floating point raster data? */
  270. int null_set; /* the colors for null are set? */
  271. unsigned char null_red;
  272. unsigned char null_grn;
  273. unsigned char null_blu;
  274. int undef_set; /* the colors for cells not in range are set? */
  275. unsigned char undef_red;
  276. unsigned char undef_grn;
  277. unsigned char undef_blu;
  278. struct _Color_Info_ fixed;
  279. struct _Color_Info_ modular;
  280. DCELL cmin;
  281. DCELL cmax;
  282. };
  283. typedef struct
  284. {
  285. unsigned char r, g, b, a; /* red, green, blue, and alpha */
  286. } RGBA_Color;
  287. typedef RGBA_Color RGB_Color;
  288. /* RGBA_Color alpha presets */
  289. #define RGBA_COLOR_OPAQUE 255
  290. #define RGBA_COLOR_TRANSPARENT 0
  291. #define RGBA_COLOR_NONE 0
  292. struct Reclass
  293. {
  294. char *name; /* name of raster map being reclassed */
  295. char *mapset; /* mapset in which "name" is found */
  296. int type; /* type of reclass */
  297. int num; /* size of reclass table */
  298. CELL min; /* table min */
  299. CELL max; /* table max */
  300. CELL *table; /* reclass table */
  301. };
  302. struct FPReclass_table
  303. {
  304. DCELL dLow; /* domain low */
  305. DCELL dHigh; /* domain high */
  306. DCELL rLow; /* range low */
  307. DCELL rHigh; /* range high */
  308. };
  309. /* reclass structure from double to double used by r.recode to reclass */
  310. /* between types: int to double, float to int,... */
  311. struct FPReclass
  312. {
  313. int defaultDRuleSet; /* 1 if default domain rule set */
  314. int defaultRRuleSet; /* 1 if default range rule set */
  315. int infiniteLeftSet; /* 1 if negative infinite interval rule exists */
  316. int infiniteRightSet; /* 1 if positive infinite interval rule exists */
  317. int rRangeSet; /* 1 if range range (i.e. interval) is set */
  318. int maxNofRules;
  319. int nofRules;
  320. DCELL defaultDMin; /* default domain minimum value */
  321. DCELL defaultDMax; /* default domain maximum value */
  322. DCELL defaultRMin; /* default range minimum value */
  323. DCELL defaultRMax; /* default range maximum value */
  324. DCELL infiniteDLeft; /* neg infinite rule */
  325. DCELL infiniteDRight; /* neg infinite rule */
  326. DCELL infiniteRLeft; /* pos infinite rule */
  327. DCELL infiniteRRight; /* pos infinite rule */
  328. DCELL dMin; /* minimum domain values in rules */
  329. DCELL dMax; /* maximum domain values in rules */
  330. DCELL rMin; /* minimum range values in rules */
  331. DCELL rMax; /* maximum range values in rules */
  332. struct FPReclass_table *table;
  333. };
  334. struct Quant_table
  335. {
  336. DCELL dLow;
  337. DCELL dHigh;
  338. CELL cLow;
  339. CELL cHigh;
  340. };
  341. struct Quant
  342. {
  343. int truncate_only;
  344. int round_only;
  345. int defaultDRuleSet;
  346. int defaultCRuleSet;
  347. int infiniteLeftSet;
  348. int infiniteRightSet;
  349. int cRangeSet;
  350. int maxNofRules;
  351. int nofRules;
  352. DCELL defaultDMin;
  353. DCELL defaultDMax;
  354. CELL defaultCMin;
  355. CELL defaultCMax;
  356. DCELL infiniteDLeft;
  357. DCELL infiniteDRight;
  358. CELL infiniteCLeft;
  359. CELL infiniteCRight;
  360. DCELL dMin;
  361. DCELL dMax;
  362. CELL cMin;
  363. CELL cMax;
  364. struct Quant_table *table;
  365. struct
  366. {
  367. DCELL *vals;
  368. /* pointers to quant rules corresponding to the intervals btwn vals */
  369. struct Quant_table **rules;
  370. int nalloc;
  371. int active;
  372. DCELL inf_dmin;
  373. DCELL inf_dmax;
  374. CELL inf_min;
  375. CELL inf_max;
  376. /* all values smaller than inf_dmin become inf_min */
  377. /* all values larger than inf_dmax become inf_max */
  378. /* inf_min and/or inf_max can be NULL if there are no inf rules */
  379. } fp_lookup;
  380. };
  381. struct Categories
  382. {
  383. CELL ncats; /* total number of categories */
  384. CELL num; /* the highest cell values. Only exists
  385. for backwards compatibility = (CELL)
  386. max_fp_values in quant rules */
  387. char *title; /* name of data layer */
  388. char *fmt; /* printf-like format to generate labels */
  389. float m1; /* Multiplication coefficient 1 */
  390. float a1; /* Addition coefficient 1 */
  391. float m2; /* Multiplication coefficient 2 */
  392. float a2; /* Addition coefficient 2 */
  393. struct Quant q; /* rules mapping cell values to index in
  394. list of labels */
  395. char **labels; /* array of labels of size num */
  396. int *marks; /* was the value with this label was used? */
  397. int nalloc;
  398. int last_marked_rule;
  399. /* NOTE: to get a rule corresponfing to cats.labels[i], use */
  400. /* G_get_ith_c/f/d_raster_cat (pcats, i, val1, val2) */
  401. /* it calls */
  402. /* G_quant_get_ith_rule(&cats->q, i, val1, val2, &index, &index); */
  403. /* and idex ==i, because rule is added at the same time as a */
  404. /* label, and quant rules are never reordered. Olga apr,95 */
  405. };
  406. struct History
  407. {
  408. char mapid[RECORD_LEN];
  409. char title[RECORD_LEN];
  410. char mapset[RECORD_LEN];
  411. char creator[RECORD_LEN];
  412. char maptype[RECORD_LEN];
  413. char datsrc_1[RECORD_LEN];
  414. char datsrc_2[RECORD_LEN];
  415. char keywrd[RECORD_LEN];
  416. int edlinecnt;
  417. char edhist[MAXEDLINES][RECORD_LEN];
  418. };
  419. struct Cell_stats
  420. {
  421. struct Cell_stats_node
  422. {
  423. int idx;
  424. long *count;
  425. int left;
  426. int right;
  427. } *node; /* tree of values */
  428. int tlen; /* allocated tree size */
  429. int N; /* number of actual nodes in tree */
  430. int curp;
  431. long null_data_count;
  432. int curoffset;
  433. };
  434. struct Histogram
  435. {
  436. int num;
  437. struct Histogram_list
  438. {
  439. CELL cat;
  440. long count;
  441. } *list;
  442. };
  443. struct Range
  444. {
  445. CELL min;
  446. CELL max;
  447. int first_time; /* whether or not range was updated */
  448. };
  449. struct FPRange
  450. {
  451. DCELL min;
  452. DCELL max;
  453. int first_time; /* whether or not range was updated */
  454. };
  455. /*
  456. ** Structure for I/O of 3dview files (view.c)
  457. */
  458. struct G_3dview
  459. {
  460. char pgm_id[40]; /* user-provided identifier */
  461. float from_to[2][3]; /* eye position & lookat position */
  462. float fov; /* field of view */
  463. float twist; /* right_hand rotation about from_to */
  464. float exag; /* terrain elevation exageration */
  465. int mesh_freq; /* cells per grid line */
  466. int poly_freq; /* cells per polygon */
  467. int display_type; /* 1 for mesh, 2 for poly, 3 for both */
  468. int lightson; /* boolean */
  469. int dozero; /* boolean */
  470. int colorgrid; /* boolean */
  471. int shading; /* boolean */
  472. int fringe; /* boolean */
  473. int surfonly; /* boolean */
  474. int doavg; /* boolean */
  475. char grid_col[40]; /* colors */
  476. char bg_col[40]; /* colors */
  477. char other_col[40]; /* colors */
  478. float lightpos[4]; /* east, north, height, 1.0 for local 0.0 infin */
  479. float lightcol[3]; /* values between 0.0 to 1.0 for red, grn, blu */
  480. float ambient;
  481. float shine;
  482. struct Cell_head vwin;
  483. };
  484. struct Key_Value
  485. {
  486. int nitems;
  487. int nalloc;
  488. char **key;
  489. char **value;
  490. };
  491. struct Option /* Structure that stores option info */
  492. {
  493. const char *key; /* Key word used on command line */
  494. int type; /* Option type */
  495. int required; /* REQUIRED or OPTIONAL */
  496. int multiple; /* Multiple entries OK */
  497. const char *options; /* Approved values or range or NULL */
  498. const char **opts; /* NULL or NULL terminated array of parsed options */
  499. const char *key_desc; /* one word describing the key */
  500. const char *label; /* Optional short label, used in GUI as item label */
  501. const char *description; /* String describing option */
  502. const char *descriptions; /* ';' separated pairs of option and option descriptions */
  503. /* For example: (with ->options = "break,rmdupl")
  504. * "break;break lines on intersections;"
  505. * "rmdupl;remove duplicates"
  506. */
  507. const char **descs; /* parsed descriptions, array of either NULL or string */
  508. /* in the same order as options */
  509. char *answer; /* Option answer */
  510. const char *def; /* Where original answer gets saved */
  511. char **answers; /* Option answers (for multiple=YES) */
  512. struct Option *next_opt; /* Pointer to next option struct */
  513. const char *gisprompt; /* Interactive prompt guidance */
  514. const char *guisection; /* GUI Layout guidance: ';' delimited heirarchical tree position */
  515. int (*checker) (); /* Routine to check answer or NULL */
  516. int count;
  517. };
  518. struct Flag /* Structure that stores flag info */
  519. {
  520. char key; /* Key char used on command line */
  521. char answer; /* Stores flag state: 0/1 */
  522. const char *label; /* Optional short label, used in GUI as item label */
  523. const char *description; /* String describing flag meaning */
  524. const char *guisection; /* GUI Layout guidance: ';' delimited heirarchical tree position */
  525. struct Flag *next_flag; /* Pointer to next flag struct */
  526. };
  527. struct GModule /* Structure that stores module info */
  528. {
  529. const char *label; /* Optional short description for GUI */
  530. const char *description; /* String describing module */
  531. const char *keywords; /* Keywords describing module */
  532. /* further items are possible: author(s), version */
  533. int overwrite; /* overwrite old files */
  534. int verbose; /* print all informations about progress and so on */
  535. };
  536. struct TimeStamp
  537. {
  538. DateTime dt[2]; /* two datetimes */
  539. int count;
  540. };
  541. struct GDAL_link;
  542. /*============================== Prototypes ================================*/
  543. /* Since there are so many prototypes for the gis library they are stored */
  544. /* in the file gisdefs.h */
  545. #include <grass/gisdefs.h>
  546. #endif /* GRASS_GIS_H */