gis.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. /* File/directory name lengths */
  83. #define GNAME_MAX 256
  84. #define GMAPSET_MAX 256
  85. #define GPATH_MAX 4096
  86. /* Macros for type size independent integers */
  87. /* Use these for portability to ensure integers are truly 32bit */
  88. /* and are handled in a uniform manner */
  89. /* Convert integer to 4 bytes - little endian */
  90. #define serialize_int32_le(buf, x) do { \
  91. (buf)[0] = ((x) >> 0) & 0xFF; \
  92. (buf)[1] = ((x) >> 8) & 0xFF; \
  93. (buf)[2] = ((x) >> 16) & 0xFF; \
  94. (buf)[3] = ((x) >> 24) & 0xFF; \
  95. } while(0)
  96. /* Convert 4 bytes to an integer - little endian */
  97. #define deserialize_int32_le(buf) (((buf)[0] << 0) | \
  98. ((buf)[1] << 8) | \
  99. ((buf)[2] << 16) | \
  100. ((buf)[3] << 24))
  101. /* Convert integer to 4 bytes - big endian */
  102. #define serialize_int32_be(buf, x) do { \
  103. (buf)[0] = ((x) >> 24) & 0xFF; \
  104. (buf)[1] = ((x) >> 16) & 0xFF; \
  105. (buf)[2] = ((x) >> 8) & 0xFF; \
  106. (buf)[3] = ((x) >> 0) & 0xFF; \
  107. } while(0)
  108. /* Convert 4 bytes to an integer - big endian */
  109. #define deserialize_int32_be(buf) (((buf)[0] << 24) | \
  110. ((buf)[1] << 16) | \
  111. ((buf)[2] << 8) | \
  112. ((buf)[3] << 0))
  113. /* Cross-platform Directory Separator Character and null device stuff */
  114. #define GRASS_DIRSEP '/'
  115. #ifdef __MINGW32__
  116. # define HOST_DIRSEP '\\'
  117. # define G_DEV_NULL "NUL:"
  118. #else
  119. # define HOST_DIRSEP '/'
  120. # define G_DEV_NULL "/dev/null"
  121. #endif
  122. /**/ typedef enum
  123. {
  124. G_OPT_DB_WHERE, /* SQL where conditions */
  125. G_OPT_DB_TABLE, /* table name */
  126. G_OPT_DB_DRIVER, /* driver name */
  127. G_OPT_DB_DATABASE, /* database name */
  128. G_OPT_DB_SCHEMA, /* database schema */
  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_V3_TYPE, /* primitive type, 2D and 3D */
  154. G_OPT_V_FIELD, /* layer number (layers used to be called fields) */
  155. G_OPT_V_CAT, /* one category */
  156. G_OPT_V_CATS, /* more categories */
  157. G_OPT_V_ID, /* one feature id */
  158. G_OPT_V_IDS, /* more feature ids */
  159. G_OPT_F_INPUT, /* old input file */
  160. G_OPT_F_OUTPUT, /* new output file */
  161. G_OPT_F_SEP, /* data field separator */
  162. G_OPT_C_FG, /* foreground color */
  163. G_OPT_C_BG /* background color */
  164. } STD_OPT;
  165. /* Message format */
  166. #define G_INFO_FORMAT_STANDARD 0 /* GRASS_MESSAGE_FORMAT=standard or not defined */
  167. #define G_INFO_FORMAT_GUI 1 /* GRASS_MESSAGE_FORMAT=gui */
  168. #define G_INFO_FORMAT_SILENT 2 /* GRASS_MESSAGE_FORMAT=silent */
  169. #define G_INFO_FORMAT_PLAIN 3 /* GRASS_MESSAGE_FORMAT=plain */
  170. /* Icon types */
  171. #define G_ICON_CROSS 0
  172. #define G_ICON_BOX 1
  173. #define G_ICON_ARROW 2
  174. /* default colors */
  175. #define DEFAULT_FG_COLOR "black"
  176. #define DEFAULT_BG_COLOR "white"
  177. /* for raster maps */
  178. #define GR_FATAL_EXIT 0
  179. #define GR_FATAL_PRINT 1
  180. #define GR_FATAL_RETURN 2
  181. /* Element types */
  182. enum
  183. { /* 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. struct Cell_head
  199. {
  200. int format; /* max number of bytes per cell minus 1 */
  201. int compressed; /* 0 = uncompressed, 1 = compressed, -1 pre 3.0 */
  202. int rows; /* number of rows in the data 2D */
  203. int rows3; /* number of rows in the data 3D */
  204. int cols; /* number of columns in the data 2D */
  205. int cols3; /* number of columns in the data 3D */
  206. int depths; /* number of depths in data */
  207. int proj; /* projection (see #defines above) */
  208. int zone; /* projection zone */
  209. double ew_res; /* east to west cell size 2D */
  210. double ew_res3; /* east to west cell size 3D */
  211. double ns_res; /* north to south cell size 2D */
  212. double ns_res3; /* north to south cell size 3D */
  213. double tb_res; /* top to bottom cell size */
  214. double north; /* coordinates of map layer */
  215. double south;
  216. double east;
  217. double west;
  218. double top;
  219. double bottom;
  220. };
  221. /*
  222. ** Structure for I/O of 3dview files (view.c)
  223. */
  224. struct G_3dview
  225. {
  226. char pgm_id[40]; /* user-provided identifier */
  227. float from_to[2][3]; /* eye position & lookat position */
  228. float fov; /* field of view */
  229. float twist; /* right_hand rotation about from_to */
  230. float exag; /* terrain elevation exageration */
  231. int mesh_freq; /* cells per grid line */
  232. int poly_freq; /* cells per polygon */
  233. int display_type; /* 1 for mesh, 2 for poly, 3 for both */
  234. int lightson; /* boolean */
  235. int dozero; /* boolean */
  236. int colorgrid; /* boolean */
  237. int shading; /* boolean */
  238. int fringe; /* boolean */
  239. int surfonly; /* boolean */
  240. int doavg; /* boolean */
  241. char grid_col[40]; /* colors */
  242. char bg_col[40]; /* colors */
  243. char other_col[40]; /* colors */
  244. float lightpos[4]; /* east, north, height, 1.0 for local 0.0 infin */
  245. float lightcol[3]; /* values between 0.0 to 1.0 for red, grn, blu */
  246. float ambient;
  247. float shine;
  248. struct Cell_head vwin;
  249. };
  250. struct Key_Value
  251. {
  252. int nitems;
  253. int nalloc;
  254. char **key;
  255. char **value;
  256. };
  257. struct Option /* Structure that stores option info */
  258. {
  259. const char *key; /* Key word used on command line */
  260. int type; /* Option type */
  261. int required; /* REQUIRED or OPTIONAL */
  262. int multiple; /* Multiple entries OK */
  263. const char *options; /* Approved values or range or NULL */
  264. const char **opts; /* NULL or NULL terminated array of parsed options */
  265. const char *key_desc; /* one word describing the key */
  266. const char *label; /* Optional short label, used in GUI as item label */
  267. const char *description; /* String describing option */
  268. const char *descriptions; /* ';' separated pairs of option and option descriptions */
  269. /* For example: (with ->options = "break,rmdupl")
  270. * "break;break lines on intersections;"
  271. * "rmdupl;remove duplicates"
  272. */
  273. const char **descs; /* parsed descriptions, array of either NULL or string */
  274. /* in the same order as options */
  275. char *answer; /* Option answer */
  276. const char *def; /* Where original answer gets saved */
  277. char **answers; /* Option answers (for multiple=YES) */
  278. struct Option *next_opt; /* Pointer to next option struct */
  279. const char *gisprompt; /* Interactive prompt guidance */
  280. const char *guisection; /* GUI Layout guidance: ';' delimited heirarchical tree position */
  281. const char *guidependency; /* GUI dependency, list of options
  282. (separated by commas) to be updated
  283. if the value is chanched */
  284. int (*checker) (); /* Routine to check answer or NULL */
  285. int count;
  286. };
  287. struct Flag /* Structure that stores flag info */
  288. {
  289. char key; /* Key char used on command line */
  290. char answer; /* Stores flag state: 0/1 */
  291. const char *label; /* Optional short label, used in GUI as item label */
  292. const char *description; /* String describing flag meaning */
  293. const char *guisection; /* GUI Layout guidance: ';' delimited heirarchical tree position */
  294. struct Flag *next_flag; /* Pointer to next flag struct */
  295. };
  296. struct GModule /* Structure that stores module info */
  297. {
  298. const char *label; /* Optional short description for GUI */
  299. const char *description; /* String describing module */
  300. const char **keywords; /* Keywords describing module */
  301. /* further items are possible: author(s), version */
  302. int overwrite; /* overwrite old files */
  303. int verbose; /* print all informations about progress and so on */
  304. };
  305. struct TimeStamp
  306. {
  307. DateTime dt[2]; /* two datetimes */
  308. int count;
  309. };
  310. struct Counter {
  311. int value;
  312. };
  313. /*============================== Prototypes ================================*/
  314. /* Since there are so many prototypes for the gis library they are stored */
  315. /* in the file gisdefs.h */
  316. #include <grass/gisdefs.h>
  317. #endif /* GRASS_GIS_H */