gis.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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. * Luca Delucchi - Italy - lucadeluge@gmail.com
  8. * PURPOSE: This file contains definitions of variables and data types
  9. * for use with most, if not all, Grass programs. This file is
  10. * usually included in every Grass program.
  11. * COPYRIGHT: (C) 2000 by the GRASS Development Team
  12. *
  13. * This program is free software under the GNU General Public
  14. * License (>=v2). Read the file COPYING that comes with GRASS
  15. * for details.
  16. *
  17. *****************************************************************************/
  18. #ifndef GRASS_GIS_H
  19. #define GRASS_GIS_H
  20. /*============================= Include Files ==============================*/
  21. /* System include files */
  22. #include <stdio.h>
  23. #include <stdarg.h>
  24. /* Grass and local include files */
  25. #include <grass/config.h>
  26. #include <grass/datetime.h>
  27. /*=========================== Constants/Defines ============================*/
  28. #if !defined __GNUC__ || __GNUC__ < 2
  29. #undef __attribute__
  30. #define __attribute__(x)
  31. #endif
  32. static const char *GRASS_copyright __attribute__ ((unused))
  33. = "GRASS GNU GPL licensed Software";
  34. #define GIS_H_VERSION "$Revision$"
  35. #define GIS_H_DATE "$Date$"
  36. #define G_gisinit(pgm) G__gisinit(GIS_H_VERSION, (pgm))
  37. #define G_no_gisinit() G__no_gisinit(GIS_H_VERSION)
  38. /* Define TRUE and FALSE for boolean comparisons */
  39. #ifndef TRUE
  40. #define TRUE 1
  41. #endif
  42. #ifndef FALSE
  43. #define FALSE 0
  44. #endif
  45. #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
  46. #define PRI_OFF_T "lld"
  47. #else
  48. #define PRI_OFF_T "ld"
  49. #endif
  50. #define NEWLINE '\n'
  51. /*!
  52. \brief List of units
  53. */
  54. #define U_UNDEFINED -1
  55. #define U_UNKNOWN 0
  56. #define U_ACRES 1
  57. #define U_HECTARES 2
  58. #define U_KILOMETERS 3
  59. #define U_METERS 4
  60. #define U_MILES 5
  61. #define U_FEET 6
  62. #define U_RADIANS 7
  63. #define U_DEGREES 8
  64. #define PROJECTION_XY 0
  65. #define PROJECTION_UTM 1
  66. #define PROJECTION_SP 2
  67. #define PROJECTION_LL 3
  68. #define PROJECTION_OTHER 99
  69. #define PROJECTION_FILE "PROJ_INFO"
  70. #define UNIT_FILE "PROJ_UNITS"
  71. #define CONFIG_DIR ".grass7"
  72. /* define PI and friends */
  73. #undef M_PI
  74. #define M_PI 3.14159265358979323846 /* pi */
  75. #undef M_PI_2
  76. #define M_PI_2 1.57079632679489661923 /* pi/2 */
  77. #undef M_PI_4
  78. #define M_PI_4 0.78539816339744830962 /* pi/4 */
  79. /* epsilon (IEEE: 2.220446e-16) */
  80. #define GRASS_EPSILON 1.0e-15
  81. /* Location of envariment variables */
  82. #define G_VAR_GISRC 0
  83. #define G_VAR_MAPSET 1
  84. /* Where to find/store variables */
  85. #define G_GISRC_MODE_FILE 0 /* files */
  86. #define G_GISRC_MODE_MEMORY 1 /* memory only */
  87. /* for G_parser() */
  88. #define TYPE_INTEGER 1
  89. #define TYPE_DOUBLE 2
  90. #define TYPE_STRING 3
  91. #define YES 1
  92. #define NO 0
  93. /* File/directory name lengths */
  94. #define GNAME_MAX 256
  95. #define GMAPSET_MAX 256
  96. #define GPATH_MAX 4096
  97. /* Macros for type size independent integers */
  98. /* Use these for portability to ensure integers are truly 32bit */
  99. /* and are handled in a uniform manner */
  100. /* Convert integer to 4 bytes - little endian */
  101. #define serialize_int32_le(buf, x) do { \
  102. (buf)[0] = ((x) >> 0) & 0xFF; \
  103. (buf)[1] = ((x) >> 8) & 0xFF; \
  104. (buf)[2] = ((x) >> 16) & 0xFF; \
  105. (buf)[3] = ((x) >> 24) & 0xFF; \
  106. } while(0)
  107. /* Convert 4 bytes to an integer - little endian */
  108. #define deserialize_int32_le(buf) (((buf)[0] << 0) | \
  109. ((buf)[1] << 8) | \
  110. ((buf)[2] << 16) | \
  111. ((buf)[3] << 24))
  112. /* Convert integer to 4 bytes - big endian */
  113. #define serialize_int32_be(buf, x) do { \
  114. (buf)[0] = ((x) >> 24) & 0xFF; \
  115. (buf)[1] = ((x) >> 16) & 0xFF; \
  116. (buf)[2] = ((x) >> 8) & 0xFF; \
  117. (buf)[3] = ((x) >> 0) & 0xFF; \
  118. } while(0)
  119. /* Convert 4 bytes to an integer - big endian */
  120. #define deserialize_int32_be(buf) (((buf)[0] << 24) | \
  121. ((buf)[1] << 16) | \
  122. ((buf)[2] << 8) | \
  123. ((buf)[3] << 0))
  124. /* Cross-platform Directory Separator Character and null device stuff */
  125. #define GRASS_DIRSEP '/'
  126. #ifdef __MINGW32__
  127. # define HOST_DIRSEP '\\'
  128. # define G_DEV_NULL "NUL:"
  129. #else
  130. # define HOST_DIRSEP '/'
  131. # define G_DEV_NULL "/dev/null"
  132. #endif
  133. /**/ typedef enum
  134. {
  135. G_OPT_UNDEFINED,
  136. G_OPT_DB_WHERE, /* SQL where conditions */
  137. G_OPT_DB_TABLE, /* table name */
  138. G_OPT_DB_DRIVER, /* driver name */
  139. G_OPT_DB_DATABASE, /* database name */
  140. G_OPT_DB_SCHEMA, /* database schema */
  141. G_OPT_DB_COLUMN, /* one attr column */
  142. G_OPT_DB_COLUMNS, /* one or more attr columns */
  143. G_OPT_DB_KEYCOLUMN, /* key column */
  144. G_OPT_I_GROUP, /* old input imagery group */
  145. G_OPT_I_SUBGROUP, /* old input imagery subgroup */
  146. G_OPT_R_INPUT, /* old input raster map */
  147. G_OPT_R_INPUTS, /* old input raster maps */
  148. G_OPT_R_OUTPUT, /* new output raster map */
  149. G_OPT_R_MAP, /* old input raster map */
  150. G_OPT_R_MAPS, /* old input rasters map */
  151. G_OPT_R_BASE, /* old input base raster map */
  152. G_OPT_R_COVER, /* old input cover raster map */
  153. G_OPT_R_ELEV, /* old input elevation raster map */
  154. G_OPT_R_ELEVS, /* old input elevation raster maps */
  155. G_OPT_R3_INPUT, /* old input raster3d map */
  156. G_OPT_R3_INPUTS, /* old input raster3d maps */
  157. G_OPT_R3_OUTPUT, /* new output raster3d map */
  158. G_OPT_R3_MAP, /* old input raster3d map */
  159. G_OPT_R3_MAPS, /* old input raster3d maps */
  160. G_OPT_R3_TYPE, /* Type (FCELL or DCELL) of a new created raster3d map */
  161. G_OPT_R3_PRECISION, /* The precision of the new generated raster3d map */
  162. G_OPT_R3_TILE_DIMENSION, /* The tile dimension of a new generated raster3d map */
  163. G_OPT_R3_COMPRESSION, /* The kind of compression of a new created raster3d map */
  164. G_OPT_V_INPUT, /* old input vector map */
  165. G_OPT_V_INPUTS, /* old input vector maps */
  166. G_OPT_V_OUTPUT, /* new output vector map */
  167. G_OPT_V_MAP, /* old input vector map */
  168. G_OPT_V_MAPS, /* old input vector maps */
  169. G_OPT_V_TYPE, /* primitive type */
  170. G_OPT_V3_TYPE, /* primitive type, 2D and 3D */
  171. G_OPT_V_FIELD, /* layer number (layers used to be called fields) */
  172. G_OPT_V_FIELD_ALL, /* layer number (layers used to be called fields) */
  173. G_OPT_V_CAT, /* one category */
  174. G_OPT_V_CATS, /* more categories */
  175. G_OPT_V_ID, /* one feature id */
  176. G_OPT_V_IDS, /* more feature ids */
  177. G_OPT_F_INPUT, /* old input file */
  178. G_OPT_F_OUTPUT, /* new output file */
  179. G_OPT_F_SEP, /* data field separator */
  180. G_OPT_DIR, /* directory input */
  181. G_OPT_C_FG, /* foreground color */
  182. G_OPT_C_BG, /* background color */
  183. G_OPT_M_UNITS, /* units */
  184. G_OPT_M_DATATYPE, /* datatype */
  185. G_OPT_M_MAPSET, /* mapset */
  186. G_OPT_M_EN, /* coordinates */
  187. G_OPT_M_COLR, /* color rules */
  188. } STD_OPT;
  189. /* Message format */
  190. #define G_INFO_FORMAT_STANDARD 0 /* GRASS_MESSAGE_FORMAT=standard or not defined */
  191. #define G_INFO_FORMAT_GUI 1 /* GRASS_MESSAGE_FORMAT=gui */
  192. #define G_INFO_FORMAT_SILENT 2 /* GRASS_MESSAGE_FORMAT=silent */
  193. #define G_INFO_FORMAT_PLAIN 3 /* GRASS_MESSAGE_FORMAT=plain */
  194. /* Icon types */
  195. #define G_ICON_CROSS 0
  196. #define G_ICON_BOX 1
  197. #define G_ICON_ARROW 2
  198. /* default colors */
  199. #define DEFAULT_FG_COLOR "black"
  200. #define DEFAULT_BG_COLOR "white"
  201. /* for raster maps */
  202. #define GR_FATAL_EXIT 0
  203. #define GR_FATAL_PRINT 1
  204. #define GR_FATAL_RETURN 2
  205. /* for vector maps */
  206. /*!
  207. \brief Name of default key column
  208. */
  209. #define GV_KEY_COLUMN "cat"
  210. /* Element types */
  211. enum
  212. { /* Dir */
  213. G_ELEMENT_RASTER = 1, /* cell */
  214. G_ELEMENT_RASTER3D = 2, /* 3dcell */
  215. G_ELEMENT_VECTOR = 3, /* vector */
  216. G_ELEMENT_OLDVECTOR = 4, /* GRASS < 5.7 vector */
  217. G_ELEMENT_ASCIIVECTOR = 5, /* ASCII vector */
  218. G_ELEMENT_ICON = 6, /* icon */
  219. G_ELEMENT_LABEL = 7, /* labels */
  220. G_ELEMENT_SITE = 8, /* sites */
  221. G_ELEMENT_REGION = 9, /* region */
  222. G_ELEMENT_REGION3D = 10, /* 3dregion */
  223. G_ELEMENT_GROUP = 11, /* group */
  224. G_ELEMENT_3DVIEW = 12 /* 3dview */
  225. };
  226. /*=========================== Typedefs/Structures ==========================*/
  227. struct Cell_head
  228. {
  229. int format; /* max number of bytes per cell minus 1 */
  230. int compressed; /* 0 = uncompressed, 1 = compressed, -1 pre 3.0 */
  231. int rows; /* number of rows in the data 2D */
  232. int rows3; /* number of rows in the data 3D */
  233. int cols; /* number of columns in the data 2D */
  234. int cols3; /* number of columns in the data 3D */
  235. int depths; /* number of depths in data */
  236. int proj; /* projection (see #defines above) */
  237. int zone; /* projection zone */
  238. double ew_res; /* east to west cell size 2D */
  239. double ew_res3; /* east to west cell size 3D */
  240. double ns_res; /* north to south cell size 2D */
  241. double ns_res3; /* north to south cell size 3D */
  242. double tb_res; /* top to bottom cell size */
  243. double north; /* coordinates of map layer */
  244. double south;
  245. double east;
  246. double west;
  247. double top;
  248. double bottom;
  249. };
  250. /*
  251. ** Structure for I/O of 3dview files (view.c)
  252. */
  253. struct G_3dview
  254. {
  255. char pgm_id[40]; /* user-provided identifier */
  256. float from_to[2][3]; /* eye position & lookat position */
  257. float fov; /* field of view */
  258. float twist; /* right_hand rotation about from_to */
  259. float exag; /* terrain elevation exageration */
  260. int mesh_freq; /* cells per grid line */
  261. int poly_freq; /* cells per polygon */
  262. int display_type; /* 1 for mesh, 2 for poly, 3 for both */
  263. int lightson; /* boolean */
  264. int dozero; /* boolean */
  265. int colorgrid; /* boolean */
  266. int shading; /* boolean */
  267. int fringe; /* boolean */
  268. int surfonly; /* boolean */
  269. int doavg; /* boolean */
  270. char grid_col[40]; /* colors */
  271. char bg_col[40]; /* colors */
  272. char other_col[40]; /* colors */
  273. float lightpos[4]; /* east, north, height, 1.0 for local 0.0 infin */
  274. float lightcol[3]; /* values between 0.0 to 1.0 for red, grn, blu */
  275. float ambient;
  276. float shine;
  277. struct Cell_head vwin;
  278. };
  279. struct Key_Value
  280. {
  281. int nitems;
  282. int nalloc;
  283. char **key;
  284. char **value;
  285. };
  286. struct Option /* Structure that stores option info */
  287. {
  288. const char *key; /* Key word used on command line */
  289. int type; /* Option type */
  290. int required; /* REQUIRED or OPTIONAL */
  291. int multiple; /* Multiple entries OK */
  292. const char *options; /* Approved values or range or NULL */
  293. const char **opts; /* NULL or NULL terminated array of parsed options */
  294. const char *key_desc; /* one word describing the key */
  295. const char *label; /* Optional short label, used in GUI as item label */
  296. const char *description; /* String describing option */
  297. const char *descriptions; /* ';' separated pairs of option and option descriptions */
  298. /* For example: (with ->options = "break,rmdupl")
  299. * "break;break lines on intersections;"
  300. * "rmdupl;remove duplicates"
  301. */
  302. const char **descs; /* parsed descriptions, array of either NULL or string */
  303. /* in the same order as options */
  304. char *answer; /* Option answer */
  305. const char *def; /* Where original answer gets saved */
  306. char **answers; /* Option answers (for multiple=YES) */
  307. struct Option *next_opt; /* Pointer to next option struct */
  308. const char *gisprompt; /* Interactive prompt guidance */
  309. const char *guisection; /* GUI Layout guidance: ';' delimited heirarchical tree position */
  310. const char *guidependency; /* GUI dependency, list of options
  311. (separated by commas) to be updated
  312. if the value is chanched */
  313. int (*checker) (); /* Routine to check answer or NULL */
  314. int count;
  315. };
  316. struct Flag /* Structure that stores flag info */
  317. {
  318. char key; /* Key char used on command line */
  319. char answer; /* Stores flag state: 0/1 */
  320. char suppress_required; /* Suppresses checking of required options */
  321. const char *label; /* Optional short label, used in GUI as item label */
  322. const char *description; /* String describing flag meaning */
  323. const char *guisection; /* GUI Layout guidance: ';' delimited heirarchical tree position */
  324. struct Flag *next_flag; /* Pointer to next flag struct */
  325. };
  326. struct GModule /* Structure that stores module info */
  327. {
  328. const char *label; /* Optional short description for GUI */
  329. const char *description; /* String describing module */
  330. const char **keywords; /* Keywords describing module */
  331. /* further items are possible: author(s), version */
  332. int overwrite; /* overwrite old files */
  333. int verbose; /* print all informations about progress and so on */
  334. };
  335. struct TimeStamp
  336. {
  337. DateTime dt[2]; /* two datetimes */
  338. int count;
  339. };
  340. struct Counter {
  341. int value;
  342. };
  343. struct Popen {
  344. FILE *fp;
  345. int pid;
  346. };
  347. typedef int CELL;
  348. typedef double DCELL;
  349. typedef float FCELL;
  350. struct _Color_Value_
  351. {
  352. DCELL value;
  353. unsigned char red;
  354. unsigned char grn;
  355. unsigned char blu;
  356. };
  357. struct _Color_Rule_
  358. {
  359. struct _Color_Value_ low, high;
  360. struct _Color_Rule_ *next;
  361. struct _Color_Rule_ *prev;
  362. };
  363. struct _Color_Info_
  364. {
  365. struct _Color_Rule_ *rules;
  366. int n_rules;
  367. struct
  368. {
  369. unsigned char *red;
  370. unsigned char *grn;
  371. unsigned char *blu;
  372. unsigned char *set;
  373. int nalloc;
  374. int active;
  375. } lookup;
  376. struct
  377. {
  378. DCELL *vals;
  379. /* pointers to color rules corresponding to the intervals btwn vals */
  380. struct _Color_Rule_ **rules;
  381. int nalloc;
  382. int active;
  383. } fp_lookup;
  384. DCELL min, max;
  385. };
  386. struct Colors
  387. {
  388. int version; /* set by read_colors: -1=old,1=new */
  389. DCELL shift;
  390. int invert;
  391. int is_float; /* defined on floating point raster data? */
  392. int null_set; /* the colors for null are set? */
  393. unsigned char null_red;
  394. unsigned char null_grn;
  395. unsigned char null_blu;
  396. int undef_set; /* the colors for cells not in range are set? */
  397. unsigned char undef_red;
  398. unsigned char undef_grn;
  399. unsigned char undef_blu;
  400. struct _Color_Info_ fixed;
  401. struct _Color_Info_ modular;
  402. DCELL cmin;
  403. DCELL cmax;
  404. int organizing;
  405. };
  406. /*============================== Prototypes ================================*/
  407. /* Since there are so many prototypes for the gis library they are stored */
  408. /* in the file gisdefs.h */
  409. #include <grass/gisdefs.h>
  410. #endif /* GRASS_GIS_H */