gis.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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 GIS_H_DATE "$Date$"
  35. #define G_gisinit(pgm) G__gisinit(GIS_H_VERSION, (pgm))
  36. #define G_no_gisinit() G__no_gisinit(GIS_H_VERSION)
  37. /* Define TRUE and FALSE for boolean comparisons */
  38. #ifndef TRUE
  39. #define TRUE 1
  40. #endif
  41. #ifndef FALSE
  42. #define FALSE 0
  43. #endif
  44. #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
  45. #define PRI_OFF_T "lld"
  46. #else
  47. #define PRI_OFF_T "ld"
  48. #endif
  49. #define NEWLINE '\n'
  50. #define METERS 1
  51. #define FEET 2
  52. #define DEGREES 3
  53. #define PROJECTION_XY 0
  54. #define PROJECTION_UTM 1
  55. #define PROJECTION_SP 2
  56. #define PROJECTION_LL 3
  57. #define PROJECTION_OTHER 99
  58. #define PROJECTION_FILE "PROJ_INFO"
  59. #define UNIT_FILE "PROJ_UNITS"
  60. #define CONFIG_DIR ".grass7"
  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 "old_color,color,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. /**/ 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_SCHEMA, /* database schema */
  130. G_OPT_DB_COLUMN, /* one attr column */
  131. G_OPT_DB_COLUMNS, /* one or more attr columns */
  132. G_OPT_I_GROUP, /* old input imagery group */
  133. G_OPT_I_SUBGROUP, /* old input imagery subgroup */
  134. G_OPT_R_INPUT, /* old input raster map */
  135. G_OPT_R_INPUTS, /* old input raster maps */
  136. G_OPT_R_OUTPUT, /* new output raster map */
  137. G_OPT_R_MAP, /* old input raster map */
  138. G_OPT_R_MAPS, /* old input rasters map */
  139. G_OPT_R_BASE, /* old input base raster map */
  140. G_OPT_R_COVER, /* old input cover raster map */
  141. G_OPT_R_ELEV, /* old input elevation raster map */
  142. G_OPT_R_ELEVS, /* old input elevation raster maps */
  143. G_OPT_R3_INPUT, /* old input raster3d map */
  144. G_OPT_R3_INPUTS, /* old input raster3d maps */
  145. G_OPT_R3_OUTPUT, /* new output raster3d map */
  146. G_OPT_R3_MAP, /* old input raster3d map */
  147. G_OPT_R3_MAPS, /* old input raster3d maps */
  148. G_OPT_V_INPUT, /* old input vector map */
  149. G_OPT_V_INPUTS, /* old input vector maps */
  150. G_OPT_V_OUTPUT, /* new output vector map */
  151. G_OPT_V_MAP, /* old input vector map */
  152. G_OPT_V_MAPS, /* old input vector maps */
  153. G_OPT_V_TYPE, /* primitive type */
  154. G_OPT_V3_TYPE, /* primitive type, 2D and 3D */
  155. G_OPT_V_FIELD, /* layer number (layers used to be called fields) */
  156. G_OPT_V_CAT, /* one category */
  157. G_OPT_V_CATS, /* more categories */
  158. G_OPT_V_ID, /* one feature id */
  159. G_OPT_V_IDS, /* more feature ids */
  160. G_OPT_F_INPUT, /* old input file */
  161. G_OPT_F_OUTPUT, /* new output file */
  162. G_OPT_F_SEP, /* data field separator */
  163. G_OPT_C_FG, /* foreground color */
  164. G_OPT_C_BG /* background color */
  165. } STD_OPT;
  166. /* Message format */
  167. #define G_INFO_FORMAT_STANDARD 0 /* GRASS_MESSAGE_FORMAT=standard or not defined */
  168. #define G_INFO_FORMAT_GUI 1 /* GRASS_MESSAGE_FORMAT=gui */
  169. #define G_INFO_FORMAT_SILENT 2 /* GRASS_MESSAGE_FORMAT=silent */
  170. #define G_INFO_FORMAT_PLAIN 3 /* GRASS_MESSAGE_FORMAT=plain */
  171. /* Icon types */
  172. #define G_ICON_CROSS 0
  173. #define G_ICON_BOX 1
  174. #define G_ICON_ARROW 2
  175. /* default colors */
  176. #define DEFAULT_FG_COLOR "black"
  177. #define DEFAULT_BG_COLOR "white"
  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. struct Cell_head
  200. {
  201. int format; /* max number of bytes per cell minus 1 */
  202. int compressed; /* 0 = uncompressed, 1 = compressed, -1 pre 3.0 */
  203. int rows; /* number of rows in the data 2D */
  204. int rows3; /* number of rows in the data 3D */
  205. int cols; /* number of columns in the data 2D */
  206. int cols3; /* number of columns in the data 3D */
  207. int depths; /* number of depths in data */
  208. int proj; /* projection (see #defines above) */
  209. int zone; /* projection zone */
  210. double ew_res; /* east to west cell size 2D */
  211. double ew_res3; /* east to west cell size 3D */
  212. double ns_res; /* north to south cell size 2D */
  213. double ns_res3; /* north to south cell size 3D */
  214. double tb_res; /* top to bottom cell size */
  215. double north; /* coordinates of map layer */
  216. double south;
  217. double east;
  218. double west;
  219. double top;
  220. double bottom;
  221. };
  222. /*
  223. ** Structure for I/O of 3dview files (view.c)
  224. */
  225. struct G_3dview
  226. {
  227. char pgm_id[40]; /* user-provided identifier */
  228. float from_to[2][3]; /* eye position & lookat position */
  229. float fov; /* field of view */
  230. float twist; /* right_hand rotation about from_to */
  231. float exag; /* terrain elevation exageration */
  232. int mesh_freq; /* cells per grid line */
  233. int poly_freq; /* cells per polygon */
  234. int display_type; /* 1 for mesh, 2 for poly, 3 for both */
  235. int lightson; /* boolean */
  236. int dozero; /* boolean */
  237. int colorgrid; /* boolean */
  238. int shading; /* boolean */
  239. int fringe; /* boolean */
  240. int surfonly; /* boolean */
  241. int doavg; /* boolean */
  242. char grid_col[40]; /* colors */
  243. char bg_col[40]; /* colors */
  244. char other_col[40]; /* colors */
  245. float lightpos[4]; /* east, north, height, 1.0 for local 0.0 infin */
  246. float lightcol[3]; /* values between 0.0 to 1.0 for red, grn, blu */
  247. float ambient;
  248. float shine;
  249. struct Cell_head vwin;
  250. };
  251. struct Key_Value
  252. {
  253. int nitems;
  254. int nalloc;
  255. char **key;
  256. char **value;
  257. };
  258. struct Option /* Structure that stores option info */
  259. {
  260. const char *key; /* Key word used on command line */
  261. int type; /* Option type */
  262. int required; /* REQUIRED or OPTIONAL */
  263. int multiple; /* Multiple entries OK */
  264. const char *options; /* Approved values or range or NULL */
  265. const char **opts; /* NULL or NULL terminated array of parsed options */
  266. const char *key_desc; /* one word describing the key */
  267. const char *label; /* Optional short label, used in GUI as item label */
  268. const char *description; /* String describing option */
  269. const char *descriptions; /* ';' separated pairs of option and option descriptions */
  270. /* For example: (with ->options = "break,rmdupl")
  271. * "break;break lines on intersections;"
  272. * "rmdupl;remove duplicates"
  273. */
  274. const char **descs; /* parsed descriptions, array of either NULL or string */
  275. /* in the same order as options */
  276. char *answer; /* Option answer */
  277. const char *def; /* Where original answer gets saved */
  278. char **answers; /* Option answers (for multiple=YES) */
  279. struct Option *next_opt; /* Pointer to next option struct */
  280. const char *gisprompt; /* Interactive prompt guidance */
  281. const char *guisection; /* GUI Layout guidance: ';' delimited heirarchical tree position */
  282. const char *guidependency; /* GUI dependency, list of options
  283. (separated by commas) to be updated
  284. if the value is chanched */
  285. int (*checker) (); /* Routine to check answer or NULL */
  286. int count;
  287. };
  288. struct Flag /* Structure that stores flag info */
  289. {
  290. char key; /* Key char used on command line */
  291. char answer; /* Stores flag state: 0/1 */
  292. const char *label; /* Optional short label, used in GUI as item label */
  293. const char *description; /* String describing flag meaning */
  294. const char *guisection; /* GUI Layout guidance: ';' delimited heirarchical tree position */
  295. struct Flag *next_flag; /* Pointer to next flag struct */
  296. };
  297. struct GModule /* Structure that stores module info */
  298. {
  299. const char *label; /* Optional short description for GUI */
  300. const char *description; /* String describing module */
  301. const char **keywords; /* Keywords describing module */
  302. /* further items are possible: author(s), version */
  303. int overwrite; /* overwrite old files */
  304. int verbose; /* print all informations about progress and so on */
  305. };
  306. struct TimeStamp
  307. {
  308. DateTime dt[2]; /* two datetimes */
  309. int count;
  310. };
  311. struct Counter {
  312. int value;
  313. };
  314. /*============================== Prototypes ================================*/
  315. /* Since there are so many prototypes for the gis library they are stored */
  316. /* in the file gisdefs.h */
  317. #include <grass/gisdefs.h>
  318. #endif /* GRASS_GIS_H */