dig_structs.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806
  1. /*!
  2. \file include/vect/dig_structs.h
  3. \brief Data structures for \ref vectorlib
  4. \author Written by Dave Gerdes (CERL) 5/1988
  5. \author Updated to GRASS 5.7 by Radim Blazek (2001)
  6. \author Updated to GRASS 7.0 by Markus Metz (2011)
  7. \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
  8. */
  9. #include <grass/config.h>
  10. #ifndef DIG___STRUCTS___
  11. #define DIG___STRUCTS___
  12. /* this file depends on <stdio.h> */
  13. #ifndef _STDIO_H
  14. #include <stdio.h>
  15. #endif
  16. #include <sys/types.h>
  17. #include <grass/dgl.h>
  18. #include <grass/shapefil.h>
  19. #include <grass/rbtree.h>
  20. #include <grass/rtree.h>
  21. #include <grass/dbmi.h>
  22. #ifdef HAVE_OGR
  23. #include <ogr_api.h>
  24. #endif
  25. #ifdef HAVE_POSTGRES
  26. #include <libpq-fe.h>
  27. #endif
  28. /*!
  29. \brief plus_t size
  30. 3.10 changes plus_t to int. This assumes that any reasonable machine
  31. will use 4 bytes to store an int. The diglib code is not guaranteed
  32. to work if plus_t is changed to a type that is larger than an int.
  33. */
  34. typedef int plus_t;
  35. /*!
  36. \brief Used by sites lib
  37. */
  38. struct site_att
  39. {
  40. /*!
  41. \brief Category number
  42. */
  43. int cat;
  44. /*!
  45. \brief Array of double attributes
  46. */
  47. double *dbl;
  48. /*!
  49. \brief Array of string attributes
  50. */
  51. char **str;
  52. };
  53. /*!
  54. \brief Bounding box
  55. */
  56. struct bound_box
  57. {
  58. /*!
  59. \brief North
  60. */
  61. double N;
  62. /*!
  63. \brief South
  64. */
  65. double S;
  66. /*!
  67. \brief East
  68. */
  69. double E;
  70. /*!
  71. \brief West
  72. */
  73. double W;
  74. /*!
  75. \brief Top
  76. */
  77. double T;
  78. /*!
  79. \brief Bottom
  80. */
  81. double B;
  82. };
  83. /*!
  84. \brief File definition
  85. */
  86. struct gvfile
  87. {
  88. /*!
  89. \brief File descriptor
  90. */
  91. FILE *file;
  92. /*!
  93. \brief Pointer to beginning of the file in the memory
  94. */
  95. char *start;
  96. /*!
  97. \brief Current position set by dig_seek()
  98. */
  99. char *current;
  100. /*!
  101. \brief End of file in the memory (pointer to first byte after)
  102. */
  103. char *end;
  104. /*!
  105. \brief Size of the file loaded to memory
  106. */
  107. off_t size;
  108. /*!
  109. \brief Allocated space
  110. */
  111. off_t alloc;
  112. /*!
  113. \brief Is file loaded?
  114. - 0 - not loaded
  115. - 1 - loaded
  116. */
  117. int loaded;
  118. };
  119. /*!
  120. \brief Layer (old: field) information
  121. */
  122. struct field_info
  123. {
  124. /*!
  125. \brief Layer number
  126. */
  127. int number;
  128. /*!
  129. \brief Layer name (optional)
  130. */
  131. char *name;
  132. /*!
  133. \brief Name of DB driver ('sqlite', 'dbf', ...)
  134. */
  135. char *driver;
  136. /*!
  137. brief Name of database
  138. */
  139. char *database;
  140. /*!
  141. \brief Name of DB table
  142. */
  143. char *table;
  144. /*!
  145. \brief Name of key column (usualy 'cat')
  146. */
  147. char *key;
  148. };
  149. /*!
  150. \brief Database links
  151. */
  152. struct dblinks
  153. {
  154. /*!
  155. \brief Pointer to the first field_info structure
  156. */
  157. struct field_info *field;
  158. /*!
  159. \brief Number of allocated slots
  160. */
  161. int alloc_fields;
  162. /*!
  163. \brief Number of available layers (old: fields)
  164. */
  165. int n_fields;
  166. };
  167. /*!
  168. \brief Portability info
  169. Set by V1_open_new() or V1_open_old()
  170. */
  171. struct Port_info
  172. {
  173. /*!
  174. \brief File byte order
  175. */
  176. int byte_order;
  177. /*!
  178. \brief Size of `off_t` data type
  179. */
  180. int off_t_size;
  181. /*!
  182. \brief Conversion matrices between file and native byte order (double)
  183. */
  184. unsigned char dbl_cnvrt[PORT_DOUBLE];
  185. /*!
  186. \brief Conversion matrices between file and native byte order (float)
  187. */
  188. unsigned char flt_cnvrt[PORT_FLOAT];
  189. /*!
  190. \brief Conversion matrices between file and native byte order (long)
  191. */
  192. unsigned char lng_cnvrt[PORT_LONG];
  193. /*!
  194. \brief Conversion matrices between file and native byte order (int)
  195. */
  196. unsigned char int_cnvrt[PORT_INT];
  197. /*!
  198. \brief Conversion matrices between file and native byte order (short)
  199. */
  200. unsigned char shrt_cnvrt[PORT_SHORT];
  201. /*!
  202. \brief Conversion matrices between file and native byte order (off_t)
  203. */
  204. unsigned char off_t_cnvrt[PORT_OFF_T];
  205. /*!
  206. \brief Quick reading flag for double
  207. Specify if native byte order of that type is the same
  208. as byte order of vector file (TRUE) or not (FALSE)
  209. */
  210. int dbl_quick;
  211. /*!
  212. \brief Quick reading flag for float
  213. Specify if native byte order of that type is the same
  214. as byte order of vector file (TRUE) or not (FALSE)
  215. */
  216. int flt_quick;
  217. /*!
  218. \brief Quick reading flag for long
  219. Specify if native byte order of that type is the same
  220. as byte order of vector file (TRUE) or not (FALSE)
  221. */
  222. int lng_quick;
  223. /*!
  224. \brief Quick reading flag for int
  225. Specify if native byte order of that type is the same
  226. as byte order of vector file (TRUE) or not (FALSE)
  227. */
  228. int int_quick;
  229. /*!
  230. \brief Quick reading flag for short
  231. Specify if native byte order of that type is the same
  232. as byte order of vector file (TRUE) or not (FALSE)
  233. */
  234. int shrt_quick;
  235. /*!
  236. \brief Quick reading flag for off_t
  237. Specify if native byte order of that type is the same
  238. as byte order of vector file (TRUE) or not (FALSE)
  239. */
  240. int off_t_quick;
  241. };
  242. /*!
  243. \brief List of dead lines in the file
  244. \todo Implement it
  245. The space can be reused, not yet used
  246. */
  247. struct recycle
  248. {
  249. char dummy;
  250. };
  251. /*! \brief Backward compatibility version info */
  252. struct Version_info {
  253. /*! \brief Current version (major) */
  254. int major;
  255. /*! \brief Current version (minor) */
  256. int minor;
  257. /*! \brief Earliest version that can use this data format (major) */
  258. int back_major;
  259. /*! \brief Earliest version that can use this data format (minor) */
  260. int back_minor;
  261. };
  262. /*!
  263. \brief Vector map header data
  264. Holds header data of vector map (see \ref vlibMap_info)
  265. */
  266. struct dig_head
  267. {
  268. /*!
  269. \brief Organization name
  270. */
  271. char *organization;
  272. /*!
  273. \brief Map date
  274. */
  275. char *date;
  276. /*!
  277. \brief User name
  278. */
  279. char *user_name;
  280. /*!
  281. \brief Map name
  282. */
  283. char *map_name;
  284. /*!
  285. \brief Source date
  286. */
  287. char *source_date;
  288. /*!
  289. \brief Original scale
  290. */
  291. long orig_scale;
  292. /*!
  293. \brief Comments
  294. */
  295. char *comment;
  296. int proj; /* projection */
  297. /*!
  298. \brief Zone (UTM only)
  299. */
  300. int plani_zone;
  301. /*!
  302. \brief Threshold for digitization
  303. */
  304. double digit_thresh;
  305. /* Programmers should NOT touch any thing below here */
  306. /* Library takes care of everything for you */
  307. /*! \brief Version info for coor file */
  308. struct Version_info coor_version;
  309. /*!
  310. \brief 2D/3D vector data
  311. - zero for 2D data
  312. - non-zero for 3D data
  313. */
  314. int with_z;
  315. /*!
  316. \brief Coor file size
  317. */
  318. off_t size;
  319. /*!
  320. \brief Coor header size
  321. */
  322. long head_size;
  323. /*!
  324. \brief Portability information
  325. */
  326. struct Port_info port;
  327. /*!
  328. \brief Offset of last read line
  329. */
  330. off_t last_offset;
  331. /*!
  332. \brief Recycle dead line
  333. \todo Not implemented yet
  334. */
  335. struct recycle *recycle;
  336. };
  337. /*!
  338. \brief Coor file info
  339. */
  340. struct Coor_info
  341. {
  342. /*!
  343. \brief Total size (in bytes)
  344. */
  345. off_t size;
  346. /*!
  347. \brief Time of last modification
  348. */
  349. long mtime;
  350. };
  351. /*!
  352. \brief Data structure used for building pseudo-topology
  353. See Vect__build_sfa() (Format_info_ogr and Format_info_pg) for
  354. implementation issues.
  355. */
  356. struct Format_info_offset
  357. {
  358. /*!
  359. \brief Offset list
  360. Array where feature/part info is stored for each feature in
  361. GRASS. This is not used for GV_CENTROID. Because one feature may
  362. contain more elements (geometry collection also recursively),
  363. offset for one line may be stored in more records. First record
  364. is FID, next records are part indexes if necessary.
  365. Example 1:
  366. 5. ring in 3. polygon in 7. feature (multipolygon) of geometry
  367. collection which has FID = 123 123 (feature 123: geometry
  368. colletion) 6 (7. feature in geometry collection: multiPolygon) 2
  369. (3. polygon) 4 (5. ring in the polygon)
  370. Example 2: geometry collection FID '1' containing one point, one
  371. linestring and one polygon
  372. \verbatim
  373. Offset:
  374. idx offset note
  375. ----------------
  376. 0 1 FID
  377. 1 0 first part (point)
  378. 2 1 FID
  379. 3 1 second part (linestring)
  380. 4 1 FID
  381. 5 2 third part (polygon)
  382. 6 0 first ring of polygon
  383. GRASS topology:
  384. line idx
  385. -----------------
  386. 1 0 point
  387. 2 2 line
  388. 3 4 boundary
  389. 4 1 centroid read from topo (idx == FID)
  390. In PostGIS Topology mode the offset array is used for mapping
  391. nodes.
  392. \endverbatim
  393. */
  394. int *array;
  395. /*!
  396. \brief Number of items in offset list
  397. */
  398. int array_num;
  399. /*!
  400. \brief Space allocated for offset list
  401. */
  402. int array_alloc;
  403. };
  404. /*!
  405. \brief Lines cache for reading feature (non-native formats)
  406. */
  407. struct Format_info_cache {
  408. /*!
  409. \brief Lines array
  410. Some simple features require more allocated lines (eg. polygon
  411. with more rings, multipoint, or geometrycollection)
  412. Line cache is also used for PostGIS Topology to store single
  413. topological element (ctype == CACHE_FEATURE) or all elements
  414. from the map (ctype == CACHE_MAP) to avoid random access which
  415. is very costly.
  416. */
  417. struct line_pnts **lines;
  418. /*!
  419. \brief List of line types (GV_POINT, GV_LINE, ...)
  420. */
  421. int *lines_types;
  422. /*!
  423. \brief List of line cats (used only for PostGIS Topology access)
  424. */
  425. int *lines_cats;
  426. /*!
  427. \brief Number of allocated lines in cache
  428. */
  429. int lines_alloc;
  430. /*!
  431. \brief Number of lines which forms current feature
  432. */
  433. int lines_num;
  434. /*!
  435. \brief Next line to be read from cache
  436. */
  437. int lines_next;
  438. /*!
  439. \brief Feature id
  440. */
  441. long fid;
  442. /*!
  443. \brief Simple feature type (currently used only by PG format)
  444. */
  445. SF_FeatureType sf_type;
  446. /*!
  447. \brief Cache type
  448. Currenly used only by PostGIS Topology which allows to cache the
  449. whole map (CACHE_MAP) */
  450. int ctype;
  451. };
  452. /*!
  453. \brief Non-native format info (OGR)
  454. \todo Structure size should not change depending on compilation I
  455. think, do it better
  456. */
  457. struct Format_info_ogr
  458. {
  459. /*!
  460. \brief OGR driver name
  461. */
  462. char *driver_name;
  463. /*!
  464. \brief OGR datasource name
  465. */
  466. char *dsn;
  467. /*!
  468. \brief OGR layer name
  469. */
  470. char *layer_name;
  471. #ifdef HAVE_OGR
  472. /*!
  473. \brief Pointer to OGRDriver
  474. */
  475. OGRSFDriverH driver;
  476. /*!
  477. \brief Pointer to OGRDataSource
  478. */
  479. OGRDataSourceH ds;
  480. /*!
  481. \brief Pointer to OGRLayer
  482. */
  483. OGRLayerH layer;
  484. #else
  485. void *driver;
  486. void *ds;
  487. void *layer;
  488. #endif
  489. /*!
  490. \brief Open DB driver when writing attributes
  491. This driver is open by V2_open_new_ogr() and closed by
  492. V1_close_ogr().
  493. */
  494. dbDriver *dbdriver;
  495. /*!
  496. \brief Array of OGR DSN options
  497. */
  498. char **dsn_options;
  499. /*!
  500. \brief Array of OGR layer options
  501. */
  502. char **layer_options;
  503. /*!
  504. \brief Lines cache for reading feature
  505. */
  506. struct Format_info_cache cache;
  507. /*!
  508. \brief Cache to avoid repeated reading (level 2)
  509. NULL if no feature is in cache
  510. */
  511. #ifdef HAVE_OGR
  512. OGRFeatureH feature_cache;
  513. #else
  514. void *feature_cache;
  515. #endif
  516. /*!
  517. \brief Offset list used for building pseudo-topology
  518. */
  519. struct Format_info_offset offset;
  520. /*!
  521. \brief Next line to be read
  522. Used by V2_read_next_line_ogr()
  523. */
  524. int next_line;
  525. };
  526. /*!
  527. \brief Non-native format info (PostGIS)
  528. */
  529. struct Format_info_pg
  530. {
  531. /*!
  532. \brief Connection string
  533. */
  534. char *conninfo;
  535. /*!
  536. \brief Database name (derived from conninfo)
  537. */
  538. char *db_name;
  539. /*!
  540. \brief Schema name
  541. */
  542. char *schema_name;
  543. /*!
  544. \brief Table name
  545. */
  546. char *table_name;
  547. /*!
  548. \brief FID column
  549. */
  550. char *fid_column;
  551. /*!
  552. \brief Geometry column (simple feature access)
  553. */
  554. char *geom_column;
  555. /*!
  556. \brief Feature type (simple feature access)
  557. */
  558. SF_FeatureType feature_type;
  559. /*!
  560. \brief Coordinates dimension (2D or 3D)
  561. */
  562. int coor_dim;
  563. /*!
  564. \brief Spatial reference system id (see spatial_ref_sys
  565. table)
  566. */
  567. int srid;
  568. /*!
  569. \brief Open DB driver when writing attributes
  570. This driver is open by V2_open_new_pg() and closed by
  571. V1_close_pg().
  572. */
  573. dbDriver *dbdriver;
  574. /*!
  575. \brief Start/Finish transaction
  576. */
  577. int inTransaction;
  578. #ifdef HAVE_POSTGRES
  579. /*!
  580. \brief PGconn object (generated by PQconnectdb)
  581. */
  582. PGconn *conn;
  583. PGresult *res;
  584. #else
  585. void *conn;
  586. void *res;
  587. #endif
  588. /*!
  589. \brief Open cursor
  590. */
  591. char *cursor_name;
  592. int cursor_fid;
  593. /*!
  594. \brief Next line to be read
  595. */
  596. int next_line;
  597. /*!
  598. \brief Lines cache for reading feature
  599. */
  600. struct Format_info_cache cache;
  601. /*!
  602. \brief Offset list used for building pseudo-topology (simple
  603. features acccess)
  604. */
  605. struct Format_info_offset offset;
  606. /* PostGIS topology support */
  607. /*!
  608. \brief TopoGeometry column (feature table)
  609. */
  610. char *topogeom_column;
  611. /*!
  612. \brief Topology schema name and id
  613. */
  614. char *toposchema_name;
  615. int toposchema_id;
  616. /*!
  617. \brief Topology format
  618. TRUE to store only Topo-Geo data in DB otherwise GRASS-like
  619. topology is also maintained in DB
  620. */
  621. int topo_geo_only;
  622. };
  623. /*!
  624. \brief Non-native format info (currently only OGR is implemented)
  625. */
  626. struct Format_info
  627. {
  628. /*!
  629. \brief id?
  630. */
  631. int i;
  632. /*!
  633. \brief OGR info
  634. */
  635. struct Format_info_ogr ogr;
  636. /*!
  637. \brief PostGIS info
  638. */
  639. struct Format_info_pg pg;
  640. };
  641. /*!
  642. \brief Category index
  643. */
  644. struct Cat_index
  645. {
  646. /*!
  647. \brief Field (layer) number
  648. */
  649. int field;
  650. /*!
  651. \brief Number of items in cat array
  652. */
  653. int n_cats;
  654. /*!
  655. \brief Allocated space in cat array
  656. */
  657. int a_cats;
  658. /*!
  659. \brief Array of cats (cat, type, lines/area)
  660. */
  661. int (*cat)[3];
  662. /*!
  663. \brief Number of unique cats (not updated)
  664. */
  665. int n_ucats;
  666. /*!
  667. \brief Number of types in type
  668. */
  669. int n_types;
  670. /*!
  671. \brief Number of elements for each type
  672. - GV_POINT
  673. - GV_LINE
  674. - GV_BOUNDARY
  675. - GV_CENTROID
  676. - GV_FACE
  677. - GV_KERNEL
  678. - GV_AREA
  679. */
  680. int type[7][2];
  681. /*!
  682. \brief Offset of the beginning of this index in cidx file
  683. */
  684. off_t offset;
  685. };
  686. /*!
  687. \brief Basic topology-related info
  688. Holds basic topology-related information about vector map
  689. Important note: you should NOT store non-topological information in
  690. topological structures.
  691. */
  692. struct Plus_head
  693. {
  694. /*! \brief Backward compatibility version info */
  695. struct {
  696. /*! \brief Version info for topology file */
  697. struct Version_info topo;
  698. /*! \brief Version info for spatial index file */
  699. struct Version_info spidx;
  700. /*! \brief Version info for category index file */
  701. struct Version_info cidx;
  702. } version;
  703. /*!
  704. \brief 2D/3D vector data
  705. - WITH_Z
  706. - WITHOUT_Z
  707. */
  708. int with_z;
  709. /*!
  710. \brief 2D/3D spatial index
  711. - WITH_Z
  712. - WITHOUT_Z
  713. */
  714. int spidx_with_z;
  715. /*!
  716. \brief Offset size
  717. Because Plus_head is available to all releveant
  718. functions
  719. */
  720. int off_t_size;
  721. /*** file header size ***/
  722. /*!
  723. \brief Topo header size
  724. */
  725. long head_size;
  726. /*!
  727. \brief Spatial index header size
  728. */
  729. long spidx_head_size;
  730. /*!
  731. \brief Category index header size
  732. */
  733. long cidx_head_size;
  734. /*!
  735. \brief Release memory occupied by support structures
  736. (topo, spatial, category)
  737. */
  738. int release_support;
  739. /*** portability info */
  740. /*!
  741. \brief Portability information
  742. */
  743. struct Port_info port;
  744. /*!
  745. \brief Portability information for spatial index
  746. */
  747. struct Port_info spidx_port;
  748. /*!
  749. \brief Portability information for category index
  750. */
  751. struct Port_info cidx_port;
  752. /*!
  753. \brief Access mode
  754. - GV_MODE_READ
  755. - GV_MODE_WRITE
  756. - GV_MODE_RW
  757. */
  758. int mode;
  759. /*!
  760. \brief Highest level of topology currently available
  761. - GV_BUILD_NONE
  762. - GV_BUILD_BASE
  763. - GV_BUILD_AREAS
  764. - GV_BUILD_ATTACH_ISLES
  765. - GV_BUILD_CENTROIDS
  766. - GV_BUILD_ALL
  767. */
  768. int built;
  769. /*!
  770. \brief Bounding box of features
  771. */
  772. struct bound_box box;
  773. /*** topology ***/
  774. /*!
  775. \brief Array of nodes
  776. */
  777. struct P_node **Node;
  778. /*!
  779. \brief Array of vector geometries
  780. */
  781. struct P_line **Line;
  782. /*!
  783. \brief Array of areas
  784. */
  785. struct P_area **Area;
  786. /*!
  787. \brief Array of isles
  788. */
  789. struct P_isle **Isle;
  790. /* add here P_FACE, P_VOLUME, P_HOLE */
  791. /*!
  792. \brief Current number of points
  793. */
  794. plus_t n_plines;
  795. /*!
  796. \brief Current number of lines
  797. */
  798. plus_t n_llines;
  799. /*!
  800. \brief Current number of boundaries
  801. */
  802. plus_t n_blines;
  803. /*!
  804. \brief Current number of centroids
  805. */
  806. plus_t n_clines;
  807. /*!
  808. \brief Current number of faces
  809. */
  810. plus_t n_flines;
  811. /*!
  812. \brief Current number of kernels
  813. */
  814. plus_t n_klines;
  815. /*!
  816. \brief Current number of volume faces
  817. */
  818. plus_t n_vfaces;
  819. /*!
  820. \brief Current number of hole faces
  821. */
  822. plus_t n_hfaces;
  823. /*!
  824. \brief Current number of topological features derived from vector
  825. geometries
  826. */
  827. /*!
  828. \brief Current number of nodes
  829. */
  830. plus_t n_nodes;
  831. /*!
  832. \brief Current number of edges
  833. */
  834. plus_t n_edges;
  835. /*!
  836. \brief Current number of lines
  837. */
  838. plus_t n_lines;
  839. /*!
  840. \brief Current number of areas
  841. */
  842. plus_t n_areas;
  843. /*!
  844. \brief Current number of isles
  845. */
  846. plus_t n_isles;
  847. /*!
  848. \brief Current number of faces
  849. */
  850. plus_t n_faces;
  851. /*!
  852. \brief Current number of volumes
  853. */
  854. plus_t n_volumes;
  855. /*!
  856. \brief Current number of holes
  857. */
  858. plus_t n_holes;
  859. /*!
  860. \brief Number of allocated nodes
  861. i.e. array size - 1
  862. */
  863. plus_t alloc_nodes;
  864. /*!
  865. \brief Number of allocated edges
  866. i.e. array size - 1
  867. */
  868. plus_t alloc_edges;
  869. /*!
  870. \brief Number of allocated lines
  871. i.e. array size - 1
  872. */
  873. plus_t alloc_lines;
  874. /*!
  875. \brief Number of allocated areas
  876. i.e. array size - 1
  877. */
  878. plus_t alloc_areas;
  879. /*!
  880. \brief Number of allocated isles
  881. i.e. array size - 1
  882. */
  883. plus_t alloc_isles;
  884. /*!
  885. \brief Number of allocated faces
  886. i.e. array size - 1
  887. */
  888. plus_t alloc_faces;
  889. /*!
  890. \brief Number of allocated volumes
  891. i.e. array size - 1
  892. */
  893. plus_t alloc_volumes;
  894. /*!
  895. \brief Number of allocated holes
  896. i.e. array size - 1
  897. */
  898. plus_t alloc_holes;
  899. /*!
  900. \brief Offset of array of nodes in topo file
  901. */
  902. off_t Node_offset;
  903. /*!
  904. \brief Offset of array of edges in topo file
  905. */
  906. off_t Edge_offset;
  907. /*!
  908. \brief Offset of array of vector geometries in topo file
  909. */
  910. off_t Line_offset;
  911. /*!
  912. \brief Offset of array of areas in topo file
  913. */
  914. off_t Area_offset;
  915. /*!
  916. \brief Offset of array of isles in topo file
  917. */
  918. off_t Isle_offset;
  919. /*!
  920. \brief Offset of array of volumes in topo file
  921. */
  922. off_t Volume_offset;
  923. /*!
  924. \brief Offset of array of holes in topo file
  925. */
  926. off_t Hole_offset;
  927. /*** spatial index ***/
  928. /*!
  929. \brief Spatial index built?
  930. Set to 1 if spatial index is available
  931. */
  932. int Spidx_built;
  933. /*!
  934. \brief Build new spatial index
  935. Set to 1 if new spatial index will be generated
  936. */
  937. int Spidx_new;
  938. /*!
  939. \brief Build new spatial index in file
  940. Set to 1 to build new indices in file
  941. */
  942. int Spidx_file;
  943. /*!
  944. \brief Spatial index file pointer
  945. */
  946. struct gvfile spidx_fp;
  947. /*!
  948. \brief Offset of nodes in sidx file
  949. */
  950. off_t Node_spidx_offset;
  951. /*!
  952. \brief Offset of lines in sidx file
  953. */
  954. off_t Line_spidx_offset;
  955. /*!
  956. \brief Offset of areas in sidx file
  957. */
  958. off_t Area_spidx_offset;
  959. /*!
  960. \brief Offset of isles in sidx file
  961. */
  962. off_t Isle_spidx_offset;
  963. /*!
  964. \brief Offset of faces in sidx file
  965. */
  966. off_t Face_spidx_offset;
  967. /*!
  968. \brief Offset of volumes in sidx file
  969. */
  970. off_t Volume_spidx_offset;
  971. /*!
  972. \brief Offset of holes in sidx file
  973. */
  974. off_t Hole_spidx_offset;
  975. /*!
  976. \brief Node spatial index
  977. */
  978. struct RTree *Node_spidx;
  979. /*!
  980. \brief Line spatial index
  981. */
  982. struct RTree *Line_spidx;
  983. /*!
  984. \brief Area spatial index
  985. */
  986. struct RTree *Area_spidx;
  987. /*!
  988. \brief Isles spatial index
  989. */
  990. struct RTree *Isle_spidx;
  991. /*!
  992. \brief Faces spatial index
  993. */
  994. struct RTree *Face_spidx;
  995. /*!
  996. \brief Volumes spatial index
  997. */
  998. struct RTree *Volume_spidx;
  999. /*!
  1000. \brief Holes spatial index
  1001. */
  1002. struct RTree *Hole_spidx;
  1003. /*** category index ***/
  1004. /*!
  1005. \brief Update category index if vector is modified
  1006. By default, category index is not updated
  1007. */
  1008. int update_cidx;
  1009. /*!
  1010. \brief Number of category indexes (one for each field/layer)
  1011. */
  1012. int n_cidx;
  1013. /*!
  1014. \brief Allocated space for category indexes
  1015. */
  1016. int a_cidx;
  1017. /*!
  1018. \brief Array of category indexes
  1019. */
  1020. struct Cat_index *cidx;
  1021. /*!
  1022. \brief Category index to be updated
  1023. Set to 1 when cidx is created
  1024. and reset to 0 whenever any line is changed
  1025. */
  1026. int cidx_up_to_date;
  1027. /*!
  1028. \brief Size of coor file
  1029. */
  1030. off_t coor_size;
  1031. /*!
  1032. \brief Time of last coor modification
  1033. */
  1034. long coor_mtime;
  1035. /*** level 2 ***/
  1036. /*!
  1037. \brief List of updated lines/nodes
  1038. Note: Vect_set_updated() must be called to maintain this list
  1039. */
  1040. struct {
  1041. /*!
  1042. \brief Indicates if the list of updated features is maintained
  1043. */
  1044. int do_uplist;
  1045. /*!
  1046. \brief Array of updated lines
  1047. List of lines and nodes updated (topo info for the line was
  1048. changed) by last write/rewrite/delete operation.
  1049. Lines/nodes in the list may be deleted (e.g. delete
  1050. boundary: first added for delete area and then delete
  1051. */
  1052. int *uplines;
  1053. /*!
  1054. \brief Array of updated lines - offset
  1055. Negative value for dead (deleted) lines - used by Vect_restore_line()
  1056. */
  1057. off_t *uplines_offset;
  1058. /*!
  1059. \brief Allocated array of lines
  1060. */
  1061. int alloc_uplines;
  1062. /*!
  1063. \brief Number of updated lines
  1064. */
  1065. int n_uplines;
  1066. /*!
  1067. \brief Array of updated nodes
  1068. */
  1069. int *upnodes;
  1070. /*!
  1071. \brief Allocated array of nodes
  1072. */
  1073. int alloc_upnodes;
  1074. /*!
  1075. \brief number of updated nodes
  1076. */
  1077. int n_upnodes;
  1078. } uplist;
  1079. };
  1080. /*!
  1081. \brief Graph-related section (see \ref dblib)
  1082. */
  1083. struct Graph_info {
  1084. /*!
  1085. \brief Line type used to build the graph
  1086. */
  1087. int line_type;
  1088. /*!
  1089. \brief Graph structure
  1090. */
  1091. dglGraph_s graph_s;
  1092. /*!
  1093. \brief Shortest path cache
  1094. */
  1095. dglSPCache_s spCache;
  1096. /*!
  1097. \brief Forward costs used for graph
  1098. dglGetEdge() is not supported for _DGL_V1)
  1099. */
  1100. double *edge_fcosts;
  1101. /*!
  1102. \brief backward costs used for graph
  1103. */
  1104. double *edge_bcosts;
  1105. /*!
  1106. \brief Node costs used for graph
  1107. */
  1108. double *node_costs;
  1109. /*!
  1110. \brief Edge and node costs multiplicator
  1111. */
  1112. int cost_multip;
  1113. };
  1114. /*! \brief
  1115. Vector map info
  1116. Maintains all information about an individual open vector map. The
  1117. structure must be passed to the most vector library routines.
  1118. */
  1119. struct Map_info
  1120. {
  1121. /*** common info for all formats ***/
  1122. /*!
  1123. \brief Map format (native, ogr, postgis)
  1124. - GV_FORMAT_NATIVE
  1125. - GV_FORMAT_OGR
  1126. - GV_FORMAT_OGR_DIRECT
  1127. - GV_FORMAT_POSTGIS
  1128. */
  1129. int format;
  1130. /*!
  1131. \brief Temporary map flag
  1132. */
  1133. int temporary;
  1134. /*!
  1135. \brief Array of DB links
  1136. */
  1137. struct dblinks *dblnk;
  1138. /*!
  1139. \brief Plus info (topology, version, ...)
  1140. */
  1141. struct Plus_head plus;
  1142. /*!
  1143. \brief Open indicator
  1144. Should be 0x5522AA22 (VECT_OPEN_CODE) if opened correctly
  1145. or 0x22AA2255 (VECT_CLOSED_CODE) if closed
  1146. Anything else implies that structure has never been initialized
  1147. */
  1148. int open;
  1149. /* Open mode
  1150. - read (GV_MODE_READ),
  1151. - write (GV_MODE_WRITE),
  1152. - rw (GV_MODE_RW)
  1153. */
  1154. int mode;
  1155. /*!
  1156. \brief Topology level
  1157. - 1 (without topo)
  1158. - 2 (with 2D topology)
  1159. - 3 (with 3D topology) - not yet implemented
  1160. */
  1161. int level;
  1162. /*!
  1163. \brief Open only header
  1164. Non-zero code to open only header of vector map
  1165. */
  1166. int head_only;
  1167. /*!
  1168. \brief Support files were updated
  1169. Non-zero code to indicate that supoort file were updated
  1170. */
  1171. int support_updated;
  1172. /*!
  1173. \brief Map name (for 4.0)
  1174. */
  1175. char *name;
  1176. /*!
  1177. \brief Mapset name
  1178. */
  1179. char *mapset;
  1180. /*!
  1181. \brief Location name
  1182. Note: location and gisdbase is useful if changed (v.proj or external apps)
  1183. */
  1184. char *location;
  1185. /*!
  1186. \brief GISDBASE path
  1187. */
  1188. char *gisdbase;
  1189. /*!
  1190. \brief Feature id for sequential access
  1191. Note: Line id starts with 1 - see Vect_read_next_line()
  1192. */
  1193. plus_t next_line;
  1194. /*!
  1195. \brief Constraints for sequential feature access
  1196. */
  1197. struct {
  1198. /*!
  1199. \brief Non-zero value to enable region constraint
  1200. */
  1201. int region_flag;
  1202. /*!
  1203. \brief Region (bbox) constraint
  1204. */
  1205. struct bound_box box;
  1206. /*!
  1207. \brief Non-zero value to enable feature type constraint
  1208. */
  1209. int type_flag;
  1210. /*!
  1211. \brief Feature type constraint
  1212. */
  1213. int type;
  1214. /*!
  1215. \brief Non-zero value to enable field constraint
  1216. */
  1217. int field_flag;
  1218. /*!
  1219. \brief Field number constraint (see line_cats structure)
  1220. */
  1221. int field;
  1222. } constraint;
  1223. /*!
  1224. \brief ???
  1225. */
  1226. int proj;
  1227. /*!
  1228. \brief History file
  1229. */
  1230. FILE *hist_fp;
  1231. /*!
  1232. \brief Graph info (built for network analysis)
  1233. */
  1234. struct Graph_info dgraph;
  1235. /*!
  1236. \brief Header info
  1237. */
  1238. struct dig_head head;
  1239. /*** format specific ***/
  1240. /*!
  1241. \brief GV file pointer (native format only)
  1242. */
  1243. struct gvfile dig_fp;
  1244. /*!
  1245. \brief Format info for non-native formats
  1246. */
  1247. struct Format_info fInfo;
  1248. /* temporary solution for sites - to be removed ?*/
  1249. /*!
  1250. \brief Array of attributes loaded from db
  1251. \todo To be removed?
  1252. */
  1253. struct site_att *site_att;
  1254. /*!
  1255. \brief Number of attributes in site_att array
  1256. \todo To be removed?
  1257. */
  1258. int n_site_att;
  1259. /*!
  1260. \brief Number of double attributes for one site
  1261. \todo To be removed
  1262. */
  1263. int n_site_dbl;
  1264. /*!
  1265. \brief Number of string attributes for one site
  1266. \todo To be removed?
  1267. */
  1268. int n_site_str;
  1269. };
  1270. /*!
  1271. \brief Topological feature - node
  1272. */
  1273. struct P_node
  1274. {
  1275. /*!
  1276. \brief X coordinate
  1277. */
  1278. double x;
  1279. /*!
  1280. \brief Y coordinate
  1281. */
  1282. double y;
  1283. /*!
  1284. \brief Z coordinate (used only for 3D data)
  1285. */
  1286. double z;
  1287. /*!
  1288. \brief Allocated space for lines
  1289. */
  1290. plus_t alloc_lines;
  1291. /*!
  1292. \brief Number of attached lines (size of
  1293. lines, angle)
  1294. If 0, then is degenerate node, for snapping ???
  1295. */
  1296. plus_t n_lines;
  1297. /*!
  1298. \brief List of connected lines
  1299. Line id can be positive (for lines which starts at the node) or
  1300. negative (for lines which ends at the node).
  1301. */
  1302. plus_t *lines;
  1303. /*!
  1304. \brief List of angles of connected lines
  1305. Angles for lines/boundaries are in radians between -PI and
  1306. PI. Value for points or lines with identical points
  1307. (degenerated) is set to -9. See dig_calc_begin_angle() and
  1308. dig_calc_end_angle() for details.
  1309. */
  1310. float *angles;
  1311. };
  1312. /*!
  1313. \brief Line topology
  1314. */
  1315. struct P_topo_l
  1316. {
  1317. /*!
  1318. \brief Start node
  1319. */
  1320. plus_t N1;
  1321. /*!
  1322. \brief End node
  1323. */
  1324. plus_t N2;
  1325. };
  1326. /*!
  1327. \brief Boundary topology
  1328. */
  1329. struct P_topo_b
  1330. {
  1331. /*!
  1332. \brief Start node
  1333. */
  1334. plus_t N1;
  1335. /*!
  1336. \brief End node
  1337. */
  1338. plus_t N2;
  1339. /*!
  1340. \brief Area number to the left, negative for isle
  1341. */
  1342. plus_t left;
  1343. /*!
  1344. \brief Area number to the right, negative for isle
  1345. */
  1346. plus_t right;
  1347. };
  1348. /*!
  1349. \brief Centroid topology
  1350. */
  1351. struct P_topo_c
  1352. {
  1353. /*!
  1354. \brief Area number, negative for duplicate centroid
  1355. */
  1356. plus_t area;
  1357. };
  1358. /*!
  1359. \brief Face topology
  1360. */
  1361. struct P_topo_f
  1362. {
  1363. /* TODO */
  1364. /*!
  1365. \brief Array of edges
  1366. */
  1367. plus_t E[3];
  1368. /*!
  1369. \brief Volume number to the left, negative for hole
  1370. */
  1371. plus_t left;
  1372. /*!
  1373. \brief Volume number to the right, negative for hole
  1374. */
  1375. plus_t right;
  1376. };
  1377. /*!
  1378. \brief Kernel topology
  1379. */
  1380. struct P_topo_k
  1381. {
  1382. /*!
  1383. \brief Volume number, negative for duplicate kernel
  1384. */
  1385. plus_t volume;
  1386. };
  1387. /*!
  1388. \brief Vector geometry
  1389. */
  1390. struct P_line
  1391. {
  1392. /*!
  1393. \brief Line type
  1394. - GV_POINT
  1395. - GV_LINE
  1396. - GV_BOUNDARY
  1397. - GV_CENTROID
  1398. - GV_FACE
  1399. - GV_KERNEL
  1400. */
  1401. char type;
  1402. /*!
  1403. \brief Offset in coor file for line
  1404. OGR-links: offset array index
  1405. PG-links: node/edge id
  1406. */
  1407. off_t offset;
  1408. /*!
  1409. \brief Topology info
  1410. NULL for points
  1411. */
  1412. void *topo;
  1413. };
  1414. /*!
  1415. \brief Area (topology) info
  1416. */
  1417. struct P_area
  1418. {
  1419. /*!
  1420. \brief Number of boundary lines
  1421. */
  1422. plus_t n_lines;
  1423. /*!
  1424. \brief Allocated space for lines
  1425. */
  1426. plus_t alloc_lines;
  1427. /*!
  1428. \brief List of boundary lines
  1429. - negative means direction N2 to N1
  1430. - lines are in clockwise order
  1431. */
  1432. plus_t *lines;
  1433. /********* Above this line is compatible with P_isle **********/
  1434. /*!
  1435. \brief Number of first centroid within area
  1436. */
  1437. plus_t centroid;
  1438. /*!
  1439. \brief Number of islands inside
  1440. */
  1441. plus_t n_isles;
  1442. /*!
  1443. \brief Allocated space for isles
  1444. */
  1445. plus_t alloc_isles;
  1446. /*!
  1447. \brief 1st generation interior islands
  1448. */
  1449. plus_t *isles;
  1450. };
  1451. /*!
  1452. \brief Isle (topology) info
  1453. */
  1454. struct P_isle
  1455. {
  1456. /*!
  1457. \brief Number of boundary lines
  1458. */
  1459. plus_t n_lines;
  1460. /*!
  1461. \brief Allocated space for lines
  1462. */
  1463. plus_t alloc_lines;
  1464. /*!
  1465. \brief List of boundary lines
  1466. - negative means direction N2 to N1
  1467. - lines are in counter clockwise order
  1468. */
  1469. plus_t *lines;
  1470. /********* Above this line is compatible with P_area **********/
  1471. /*!
  1472. \brief Area it exists w/in, if any
  1473. */
  1474. plus_t area;
  1475. };
  1476. /*!
  1477. \brief Feature geometry info - coordinates
  1478. */
  1479. struct line_pnts
  1480. {
  1481. /*!
  1482. \brief Array of X coordinates
  1483. */
  1484. double *x;
  1485. /*!
  1486. \brief Array of Y coordinates
  1487. */
  1488. double *y;
  1489. /*!
  1490. \brief Array of Z coordinates
  1491. */
  1492. double *z;
  1493. /*!
  1494. \brief Number of points
  1495. */
  1496. int n_points;
  1497. /*!
  1498. \brief Allocated space for points
  1499. */
  1500. int alloc_points;
  1501. };
  1502. /*!
  1503. \brief Feature category info
  1504. */
  1505. struct line_cats
  1506. {
  1507. /*!
  1508. \brief Array of layers (fields)
  1509. */
  1510. int *field;
  1511. /*!
  1512. \brief Array of categories
  1513. */
  1514. int *cat;
  1515. /*!
  1516. \brief Number of categories attached to element
  1517. */
  1518. int n_cats;
  1519. /*!
  1520. \brief Allocated space for categories
  1521. */
  1522. int alloc_cats;
  1523. };
  1524. /*! \brief Category list */
  1525. struct cat_list
  1526. {
  1527. /*!
  1528. \brief Category layer (field)
  1529. */
  1530. int field;
  1531. /*!
  1532. \brief Array of minimum values
  1533. */
  1534. int *min;
  1535. /*!
  1536. \brief Array of maximum values
  1537. */
  1538. int *max;
  1539. /*!
  1540. \brief Number of ranges
  1541. */
  1542. int n_ranges;
  1543. /*!
  1544. \brief Allocated space for ranges
  1545. */
  1546. int alloc_ranges;
  1547. };
  1548. /*!
  1549. \brief List of bounding boxes with id
  1550. */
  1551. struct boxlist
  1552. {
  1553. /*!
  1554. \brief Array of ids
  1555. */
  1556. int *id;
  1557. /*!
  1558. \brief Array of bounding boxes
  1559. */
  1560. struct bound_box *box;
  1561. /*!
  1562. \brief flag to indicate whether bounding boxes should be added
  1563. */
  1564. int have_boxes;
  1565. /*!
  1566. \brief Number of items in the list
  1567. */
  1568. int n_values;
  1569. /*!
  1570. \brief Allocated space for items
  1571. */
  1572. int alloc_values;
  1573. };
  1574. /*!
  1575. \brief Vector array
  1576. Space allocated is size + 1
  1577. */
  1578. struct varray
  1579. {
  1580. /*!
  1581. \brief Array size
  1582. */
  1583. int size;
  1584. /*!
  1585. \brief Array
  1586. Where 'class' or new category
  1587. or something like that is stored
  1588. */
  1589. int *c;
  1590. };
  1591. /*!
  1592. \brief Spatial index info
  1593. For use in modules
  1594. */
  1595. struct spatial_index
  1596. {
  1597. /*!
  1598. \brief Pointer to the search tree (R*-Tree)
  1599. */
  1600. struct RTree *si_tree;
  1601. /*!
  1602. \brief Name of file to store the search tree
  1603. */
  1604. char *name;
  1605. };
  1606. #endif /* DIG___STRUCTS___ */