dig_structs.h 33 KB

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