gis.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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: 37043 $"
  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. #define NEWLINE '\n'
  45. #define METERS 1
  46. #define FEET 2
  47. #define DEGREES 3
  48. #define PROJECTION_XY 0
  49. #define PROJECTION_UTM 1
  50. #define PROJECTION_SP 2
  51. #define PROJECTION_LL 3
  52. #define PROJECTION_OTHER 99
  53. #define PROJECTION_FILE "PROJ_INFO"
  54. #define UNIT_FILE "PROJ_UNITS"
  55. /* define PI and friends */
  56. #undef M_PI
  57. #define M_PI 3.14159265358979323846 /* pi */
  58. #undef M_PI_2
  59. #define M_PI_2 1.57079632679489661923 /* pi/2 */
  60. #undef M_PI_4
  61. #define M_PI_4 0.78539816339744830962 /* pi/4 */
  62. /* epsilon (IEEE: 2.220446e-16) */
  63. #define GRASS_EPSILON 1.0e-15
  64. /* Location of envariment variables */
  65. #define G_VAR_GISRC 0
  66. #define G_VAR_MAPSET 1
  67. /* Where to find/store variables */
  68. #define G_GISRC_MODE_FILE 0 /* files */
  69. #define G_GISRC_MODE_MEMORY 1 /* memory only */
  70. /* for G_parser() */
  71. #define TYPE_INTEGER 1
  72. #define TYPE_DOUBLE 2
  73. #define TYPE_STRING 3
  74. #define YES 1
  75. #define NO 0
  76. #define GISPROMPT_COLOR "old_color,color,color"
  77. /* File/directory name lengths */
  78. #define GNAME_MAX 256
  79. #define GMAPSET_MAX 256
  80. #define GPATH_MAX 4096
  81. /* Macros for type size independent integers */
  82. /* Use these for portability to ensure integers are truly 32bit */
  83. /* and are handled in a uniform manner */
  84. /* Convert integer to 4 bytes - little endian */
  85. #define serialize_int32_le(buf, x) do { \
  86. (buf)[0] = ((x) >> 0) & 0xFF; \
  87. (buf)[1] = ((x) >> 8) & 0xFF; \
  88. (buf)[2] = ((x) >> 16) & 0xFF; \
  89. (buf)[3] = ((x) >> 24) & 0xFF; \
  90. } while(0)
  91. /* Convert 4 bytes to an integer - little endian */
  92. #define deserialize_int32_le(buf) (((buf)[0] << 0) | \
  93. ((buf)[1] << 8) | \
  94. ((buf)[2] << 16) | \
  95. ((buf)[3] << 24))
  96. /* Convert integer to 4 bytes - big endian */
  97. #define serialize_int32_be(buf, x) do { \
  98. (buf)[0] = ((x) >> 24) & 0xFF; \
  99. (buf)[1] = ((x) >> 16) & 0xFF; \
  100. (buf)[2] = ((x) >> 8) & 0xFF; \
  101. (buf)[3] = ((x) >> 0) & 0xFF; \
  102. } while(0)
  103. /* Convert 4 bytes to an integer - big endian */
  104. #define deserialize_int32_be(buf) (((buf)[0] << 24) | \
  105. ((buf)[1] << 16) | \
  106. ((buf)[2] << 8) | \
  107. ((buf)[3] << 0))
  108. /* Cross-platform Directory Separator Character and null device stuff */
  109. #define GRASS_DIRSEP '/'
  110. #ifdef __MINGW32__
  111. # define HOST_DIRSEP '\\'
  112. # define G_DEV_NULL "NUL:"
  113. #else
  114. # define HOST_DIRSEP '/'
  115. # define G_DEV_NULL "/dev/null"
  116. #endif
  117. /**/ typedef enum
  118. {
  119. G_OPT_DB_WHERE, /* SQL where conditions */
  120. G_OPT_DB_TABLE, /* table name */
  121. G_OPT_DB_DRIVER, /* driver name */
  122. G_OPT_DB_DATABASE, /* database name */
  123. G_OPT_DB_COLUMN, /* one attr column */
  124. G_OPT_DB_COLUMNS, /* one or more attr columns */
  125. G_OPT_I_GROUP, /* old input imagery group */
  126. G_OPT_I_SUBGROUP, /* old input imagery subgroup */
  127. G_OPT_R_INPUT, /* old input raster map */
  128. G_OPT_R_INPUTS, /* old input raster maps */
  129. G_OPT_R_OUTPUT, /* new output raster map */
  130. G_OPT_R_MAP, /* old input raster map */
  131. G_OPT_R_MAPS, /* old input rasters map */
  132. G_OPT_R_BASE, /* old input base raster map */
  133. G_OPT_R_COVER, /* old input cover raster map */
  134. G_OPT_R_ELEV, /* old input elevation raster map */
  135. G_OPT_R_ELEVS, /* old input elevation raster maps */
  136. G_OPT_R3_INPUT, /* old input raster3d map */
  137. G_OPT_R3_INPUTS, /* old input raster3d maps */
  138. G_OPT_R3_OUTPUT, /* new output raster3d map */
  139. G_OPT_R3_MAP, /* old input raster3d map */
  140. G_OPT_R3_MAPS, /* old input raster3d maps */
  141. G_OPT_V_INPUT, /* old input vector map */
  142. G_OPT_V_INPUTS, /* old input vector maps */
  143. G_OPT_V_OUTPUT, /* new output vector map */
  144. G_OPT_V_MAP, /* old input vector map */
  145. G_OPT_V_MAPS, /* old input vector maps */
  146. G_OPT_V_TYPE, /* primitive type */
  147. G_OPT_V_FIELD, /* layer number (layers used to be called fields) */
  148. G_OPT_V_CAT, /* one category */
  149. G_OPT_V_CATS, /* more categories */
  150. G_OPT_V_ID, /* one feature id */
  151. G_OPT_V_IDS, /* more feature ids */
  152. G_OPT_F_INPUT, /* old input file */
  153. G_OPT_F_OUTPUT, /* new output file */
  154. G_OPT_F_SEP, /* data field separator */
  155. G_OPT_C_FG, /* foreground color */
  156. G_OPT_C_BG /* background color */
  157. } STD_OPT;
  158. /* Message format */
  159. #define G_INFO_FORMAT_STANDARD 0 /* GRASS_MESSAGE_FORMAT=standard or not defined */
  160. #define G_INFO_FORMAT_GUI 1 /* GRASS_MESSAGE_FORMAT=gui */
  161. #define G_INFO_FORMAT_SILENT 2 /* GRASS_MESSAGE_FORMAT=silent */
  162. #define G_INFO_FORMAT_PLAIN 3 /* GRASS_MESSAGE_FORMAT=plain */
  163. /* Icon types */
  164. #define G_ICON_CROSS 0
  165. #define G_ICON_BOX 1
  166. #define G_ICON_ARROW 2
  167. /* default colors */
  168. #define DEFAULT_FG_COLOR "black"
  169. #define DEFAULT_BG_COLOR "white"
  170. /* for raster maps */
  171. #define GR_FATAL_EXIT 0
  172. #define GR_FATAL_PRINT 1
  173. #define GR_FATAL_RETURN 2
  174. /* Element types */
  175. enum
  176. { /* Dir */
  177. G_ELEMENT_RASTER = 1, /* cell */
  178. G_ELEMENT_RASTER3D = 2, /* 3dcell */
  179. G_ELEMENT_VECTOR = 3, /* vector */
  180. G_ELEMENT_OLDVECTOR = 4, /* GRASS < 5.7 vector */
  181. G_ELEMENT_ASCIIVECTOR = 5, /* ASCII vector */
  182. G_ELEMENT_ICON = 6, /* icon */
  183. G_ELEMENT_LABEL = 7, /* labels */
  184. G_ELEMENT_SITE = 8, /* sites */
  185. G_ELEMENT_REGION = 9, /* region */
  186. G_ELEMENT_REGION3D = 10, /* 3dregion */
  187. G_ELEMENT_GROUP = 11, /* group */
  188. G_ELEMENT_3DVIEW = 12 /* 3dview */
  189. };
  190. /*=========================== Typedefs/Structures ==========================*/
  191. struct Cell_head
  192. {
  193. int format; /* max number of bytes per cell minus 1 */
  194. int compressed; /* 0 = uncompressed, 1 = compressed, -1 pre 3.0 */
  195. int rows; /* number of rows in the data 2D */
  196. int rows3; /* number of rows in the data 3D */
  197. int cols; /* number of columns in the data 2D */
  198. int cols3; /* number of columns in the data 3D */
  199. int depths; /* number of depths in data */
  200. int proj; /* projection (see #defines above) */
  201. int zone; /* projection zone */
  202. double ew_res; /* east to west cell size 2D */
  203. double ew_res3; /* east to west cell size 3D */
  204. double ns_res; /* north to south cell size 2D */
  205. double ns_res3; /* north to south cell size 3D */
  206. double tb_res; /* top to bottom cell size */
  207. double north; /* coordinates of map layer */
  208. double south;
  209. double east;
  210. double west;
  211. double top;
  212. double bottom;
  213. };
  214. /*
  215. ** Structure for I/O of 3dview files (view.c)
  216. */
  217. struct G_3dview
  218. {
  219. char pgm_id[40]; /* user-provided identifier */
  220. float from_to[2][3]; /* eye position & lookat position */
  221. float fov; /* field of view */
  222. float twist; /* right_hand rotation about from_to */
  223. float exag; /* terrain elevation exageration */
  224. int mesh_freq; /* cells per grid line */
  225. int poly_freq; /* cells per polygon */
  226. int display_type; /* 1 for mesh, 2 for poly, 3 for both */
  227. int lightson; /* boolean */
  228. int dozero; /* boolean */
  229. int colorgrid; /* boolean */
  230. int shading; /* boolean */
  231. int fringe; /* boolean */
  232. int surfonly; /* boolean */
  233. int doavg; /* boolean */
  234. char grid_col[40]; /* colors */
  235. char bg_col[40]; /* colors */
  236. char other_col[40]; /* colors */
  237. float lightpos[4]; /* east, north, height, 1.0 for local 0.0 infin */
  238. float lightcol[3]; /* values between 0.0 to 1.0 for red, grn, blu */
  239. float ambient;
  240. float shine;
  241. struct Cell_head vwin;
  242. };
  243. struct Key_Value
  244. {
  245. int nitems;
  246. int nalloc;
  247. char **key;
  248. char **value;
  249. };
  250. struct Option /* Structure that stores option info */
  251. {
  252. const char *key; /* Key word used on command line */
  253. int type; /* Option type */
  254. int required; /* REQUIRED or OPTIONAL */
  255. int multiple; /* Multiple entries OK */
  256. const char *options; /* Approved values or range or NULL */
  257. const char **opts; /* NULL or NULL terminated array of parsed options */
  258. const char *key_desc; /* one word describing the key */
  259. const char *label; /* Optional short label, used in GUI as item label */
  260. const char *description; /* String describing option */
  261. const char *descriptions; /* ';' separated pairs of option and option descriptions */
  262. /* For example: (with ->options = "break,rmdupl")
  263. * "break;break lines on intersections;"
  264. * "rmdupl;remove duplicates"
  265. */
  266. const char **descs; /* parsed descriptions, array of either NULL or string */
  267. /* in the same order as options */
  268. char *answer; /* Option answer */
  269. const char *def; /* Where original answer gets saved */
  270. char **answers; /* Option answers (for multiple=YES) */
  271. struct Option *next_opt; /* Pointer to next option struct */
  272. const char *gisprompt; /* Interactive prompt guidance */
  273. const char *guisection; /* GUI Layout guidance: ';' delimited heirarchical tree position */
  274. int (*checker) (); /* Routine to check answer or NULL */
  275. int count;
  276. };
  277. struct Flag /* Structure that stores flag info */
  278. {
  279. char key; /* Key char used on command line */
  280. char answer; /* Stores flag state: 0/1 */
  281. const char *label; /* Optional short label, used in GUI as item label */
  282. const char *description; /* String describing flag meaning */
  283. const char *guisection; /* GUI Layout guidance: ';' delimited heirarchical tree position */
  284. struct Flag *next_flag; /* Pointer to next flag struct */
  285. };
  286. struct GModule /* Structure that stores module info */
  287. {
  288. const char *label; /* Optional short description for GUI */
  289. const char *description; /* String describing module */
  290. const char **keywords; /* Keywords describing module */
  291. /* further items are possible: author(s), version */
  292. int overwrite; /* overwrite old files */
  293. int verbose; /* print all informations about progress and so on */
  294. };
  295. struct TimeStamp
  296. {
  297. DateTime dt[2]; /* two datetimes */
  298. int count;
  299. };
  300. struct Counter {
  301. int value;
  302. };
  303. /*============================== Prototypes ================================*/
  304. /* Since there are so many prototypes for the gis library they are stored */
  305. /* in the file gisdefs.h */
  306. #include <grass/gisdefs.h>
  307. #endif /* GRASS_GIS_H */