dig_structs.h 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804
  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 (usualy '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. Currenly used only by PostGIS Topology which allows to cache 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. #ifdef HAVE_OGR
  469. /*!
  470. \brief Pointer to OGRDriver
  471. */
  472. OGRSFDriverH driver;
  473. /*!
  474. \brief Pointer to OGRDataSource
  475. */
  476. OGRDataSourceH ds;
  477. /*!
  478. \brief Pointer to OGRLayer
  479. */
  480. OGRLayerH layer;
  481. #else
  482. void *driver;
  483. void *ds;
  484. void *layer;
  485. #endif
  486. /*!
  487. \brief Open DB driver when writing attributes
  488. This driver is open by V2_open_new_ogr() and closed by
  489. V1_close_ogr().
  490. */
  491. dbDriver *dbdriver;
  492. /*!
  493. \brief Array of OGR DSN options
  494. */
  495. char **dsn_options;
  496. /*!
  497. \brief Array of OGR layer options
  498. */
  499. char **layer_options;
  500. /*!
  501. \brief Lines cache for reading feature
  502. */
  503. struct Format_info_cache cache;
  504. /*!
  505. \brief Cache to avoid repeated reading (level 2)
  506. NULL if no feature is in cache
  507. */
  508. #ifdef HAVE_OGR
  509. OGRFeatureH feature_cache;
  510. #else
  511. void *feature_cache;
  512. #endif
  513. /*!
  514. \brief Offset list used for building pseudo-topology
  515. */
  516. struct Format_info_offset offset;
  517. /*!
  518. \brief Next line to be read
  519. Used by V2_read_next_line_ogr()
  520. */
  521. int next_line;
  522. };
  523. /*!
  524. \brief Non-native format info (PostGIS)
  525. */
  526. struct Format_info_pg
  527. {
  528. /*!
  529. \brief Connection string
  530. */
  531. char *conninfo;
  532. /*!
  533. \brief Database name (derived from conninfo)
  534. */
  535. char *db_name;
  536. /*!
  537. \brief Schema name
  538. */
  539. char *schema_name;
  540. /*!
  541. \brief Table name
  542. */
  543. char *table_name;
  544. /*!
  545. \brief FID column
  546. */
  547. char *fid_column;
  548. /*!
  549. \brief Geometry column (simple feature access)
  550. */
  551. char *geom_column;
  552. /*!
  553. \brief Feature type (simple feature access)
  554. */
  555. SF_FeatureType feature_type;
  556. /*!
  557. \brief Coordinates dimension (2D or 3D)
  558. */
  559. int coor_dim;
  560. /*!
  561. \brief Spatial reference system id (see spatial_ref_sys
  562. table)
  563. */
  564. int srid;
  565. /*!
  566. \brief Open DB driver when writing attributes
  567. This driver is open by V2_open_new_pg() and closed by
  568. V1_close_pg().
  569. */
  570. dbDriver *dbdriver;
  571. struct field_info *fi;
  572. /*!
  573. \brief Start/Finish transaction
  574. */
  575. int inTransaction;
  576. #ifdef HAVE_POSTGRES
  577. /*!
  578. \brief PGconn object (generated by PQconnectdb)
  579. */
  580. PGconn *conn;
  581. PGresult *res;
  582. #else
  583. void *conn;
  584. void *res;
  585. #endif
  586. /*!
  587. \brief Open cursor
  588. */
  589. char *cursor_name;
  590. int cursor_fid;
  591. /*!
  592. \brief Next line to be read
  593. */
  594. int next_line;
  595. /*!
  596. \brief Lines cache for reading feature
  597. */
  598. struct Format_info_cache cache;
  599. /*!
  600. \brief Offset list used for building pseudo-topology (simple
  601. features acccess)
  602. */
  603. struct Format_info_offset offset;
  604. /* PostGIS topology support */
  605. /*!
  606. \brief TopoGeometry column (feature table)
  607. */
  608. char *topogeom_column;
  609. /*!
  610. \brief Topology schema name and id
  611. */
  612. char *toposchema_name;
  613. int toposchema_id;
  614. /*!
  615. \brief Topology format
  616. TRUE to store only Topo-Geo data in DB otherwise GRASS-like
  617. topology is also maintained in DB
  618. */
  619. int topo_geo_only;
  620. };
  621. /*!
  622. \brief Non-native format info (currently only OGR is implemented)
  623. */
  624. struct Format_info
  625. {
  626. /*!
  627. \brief id?
  628. */
  629. int i;
  630. /*!
  631. \brief OGR info
  632. */
  633. struct Format_info_ogr ogr;
  634. /*!
  635. \brief PostGIS info
  636. */
  637. struct Format_info_pg pg;
  638. };
  639. /*!
  640. \brief Category index
  641. */
  642. struct Cat_index
  643. {
  644. /*!
  645. \brief Field (layer) number
  646. */
  647. int field;
  648. /*!
  649. \brief Number of items in cat array
  650. */
  651. int n_cats;
  652. /*!
  653. \brief Allocated space in cat array
  654. */
  655. int a_cats;
  656. /*!
  657. \brief Array of cats (cat, type, lines/area)
  658. */
  659. int (*cat)[3];
  660. /*!
  661. \brief Number of unique cats (not updated)
  662. */
  663. int n_ucats;
  664. /*!
  665. \brief Number of types in type
  666. */
  667. int n_types;
  668. /*!
  669. \brief Number of elements for each type
  670. - GV_POINT
  671. - GV_LINE
  672. - GV_BOUNDARY
  673. - GV_CENTROID
  674. - GV_FACE
  675. - GV_KERNEL
  676. - GV_AREA
  677. */
  678. int type[7][2];
  679. /*!
  680. \brief Offset of the beginning of this index in cidx file
  681. */
  682. off_t offset;
  683. };
  684. /*!
  685. \brief Basic topology-related info
  686. Holds basic topology-related information about vector map
  687. Important note: you should NOT store non-topological information in
  688. topological structures.
  689. */
  690. struct Plus_head
  691. {
  692. /*! \brief Backward compatibility version info */
  693. struct {
  694. /*! \brief Version info for topology file */
  695. struct Version_info topo;
  696. /*! \brief Version info for spatial index file */
  697. struct Version_info spidx;
  698. /*! \brief Version info for category index file */
  699. struct Version_info cidx;
  700. } version;
  701. /*!
  702. \brief 2D/3D vector data
  703. - WITH_Z
  704. - WITHOUT_Z
  705. */
  706. int with_z;
  707. /*!
  708. \brief 2D/3D spatial index
  709. - WITH_Z
  710. - WITHOUT_Z
  711. */
  712. int spidx_with_z;
  713. /*!
  714. \brief Offset size
  715. Because Plus_head is available to all releveant
  716. functions
  717. */
  718. int off_t_size;
  719. /*** file header size ***/
  720. /*!
  721. \brief Topo header size
  722. */
  723. long head_size;
  724. /*!
  725. \brief Spatial index header size
  726. */
  727. long spidx_head_size;
  728. /*!
  729. \brief Category index header size
  730. */
  731. long cidx_head_size;
  732. /*!
  733. \brief Release memory occupied by support structures
  734. (topo, spatial, category)
  735. */
  736. int release_support;
  737. /*** portability info */
  738. /*!
  739. \brief Portability information
  740. */
  741. struct Port_info port;
  742. /*!
  743. \brief Portability information for spatial index
  744. */
  745. struct Port_info spidx_port;
  746. /*!
  747. \brief Portability information for category index
  748. */
  749. struct Port_info cidx_port;
  750. /*!
  751. \brief Access mode
  752. - GV_MODE_READ
  753. - GV_MODE_WRITE
  754. - GV_MODE_RW
  755. */
  756. int mode;
  757. /*!
  758. \brief Highest level of topology currently available
  759. - GV_BUILD_NONE
  760. - GV_BUILD_BASE
  761. - GV_BUILD_AREAS
  762. - GV_BUILD_ATTACH_ISLES
  763. - GV_BUILD_CENTROIDS
  764. - GV_BUILD_ALL
  765. */
  766. int built;
  767. /*!
  768. \brief Bounding box of features
  769. */
  770. struct bound_box box;
  771. /*** topology ***/
  772. /*!
  773. \brief Array of nodes
  774. */
  775. struct P_node **Node;
  776. /*!
  777. \brief Array of vector geometries
  778. */
  779. struct P_line **Line;
  780. /*!
  781. \brief Array of areas
  782. */
  783. struct P_area **Area;
  784. /*!
  785. \brief Array of isles
  786. */
  787. struct P_isle **Isle;
  788. /* add here P_FACE, P_VOLUME, P_HOLE */
  789. /*!
  790. \brief Current number of points
  791. */
  792. plus_t n_plines;
  793. /*!
  794. \brief Current number of lines
  795. */
  796. plus_t n_llines;
  797. /*!
  798. \brief Current number of boundaries
  799. */
  800. plus_t n_blines;
  801. /*!
  802. \brief Current number of centroids
  803. */
  804. plus_t n_clines;
  805. /*!
  806. \brief Current number of faces
  807. */
  808. plus_t n_flines;
  809. /*!
  810. \brief Current number of kernels
  811. */
  812. plus_t n_klines;
  813. /*!
  814. \brief Current number of volume faces
  815. */
  816. plus_t n_vfaces;
  817. /*!
  818. \brief Current number of hole faces
  819. */
  820. plus_t n_hfaces;
  821. /*!
  822. \brief Current number of topological features derived from vector
  823. geometries
  824. */
  825. /*!
  826. \brief Current number of nodes
  827. */
  828. plus_t n_nodes;
  829. /*!
  830. \brief Current number of edges
  831. */
  832. plus_t n_edges;
  833. /*!
  834. \brief Current number of lines
  835. */
  836. plus_t n_lines;
  837. /*!
  838. \brief Current number of areas
  839. */
  840. plus_t n_areas;
  841. /*!
  842. \brief Current number of isles
  843. */
  844. plus_t n_isles;
  845. /*!
  846. \brief Current number of faces
  847. */
  848. plus_t n_faces;
  849. /*!
  850. \brief Current number of volumes
  851. */
  852. plus_t n_volumes;
  853. /*!
  854. \brief Current number of holes
  855. */
  856. plus_t n_holes;
  857. /*!
  858. \brief Number of allocated nodes
  859. i.e. array size - 1
  860. */
  861. plus_t alloc_nodes;
  862. /*!
  863. \brief Number of allocated edges
  864. i.e. array size - 1
  865. */
  866. plus_t alloc_edges;
  867. /*!
  868. \brief Number of allocated lines
  869. i.e. array size - 1
  870. */
  871. plus_t alloc_lines;
  872. /*!
  873. \brief Number of allocated areas
  874. i.e. array size - 1
  875. */
  876. plus_t alloc_areas;
  877. /*!
  878. \brief Number of allocated isles
  879. i.e. array size - 1
  880. */
  881. plus_t alloc_isles;
  882. /*!
  883. \brief Number of allocated faces
  884. i.e. array size - 1
  885. */
  886. plus_t alloc_faces;
  887. /*!
  888. \brief Number of allocated volumes
  889. i.e. array size - 1
  890. */
  891. plus_t alloc_volumes;
  892. /*!
  893. \brief Number of allocated holes
  894. i.e. array size - 1
  895. */
  896. plus_t alloc_holes;
  897. /*!
  898. \brief Offset of array of nodes in topo file
  899. */
  900. off_t Node_offset;
  901. /*!
  902. \brief Offset of array of edges in topo file
  903. */
  904. off_t Edge_offset;
  905. /*!
  906. \brief Offset of array of vector geometries in topo file
  907. */
  908. off_t Line_offset;
  909. /*!
  910. \brief Offset of array of areas in topo file
  911. */
  912. off_t Area_offset;
  913. /*!
  914. \brief Offset of array of isles in topo file
  915. */
  916. off_t Isle_offset;
  917. /*!
  918. \brief Offset of array of volumes in topo file
  919. */
  920. off_t Volume_offset;
  921. /*!
  922. \brief Offset of array of holes in topo file
  923. */
  924. off_t Hole_offset;
  925. /*** spatial index ***/
  926. /*!
  927. \brief Spatial index built?
  928. Set to 1 if spatial index is available
  929. */
  930. int Spidx_built;
  931. /*!
  932. \brief Build new spatial index
  933. Set to 1 if new spatial index will be generated
  934. */
  935. int Spidx_new;
  936. /*!
  937. \brief Build new spatial index in file
  938. Set to 1 to build new indices in file
  939. */
  940. int Spidx_file;
  941. /*!
  942. \brief Spatial index file pointer
  943. */
  944. struct gvfile spidx_fp;
  945. /*!
  946. \brief Offset of nodes in sidx file
  947. */
  948. off_t Node_spidx_offset;
  949. /*!
  950. \brief Offset of lines in sidx file
  951. */
  952. off_t Line_spidx_offset;
  953. /*!
  954. \brief Offset of areas in sidx file
  955. */
  956. off_t Area_spidx_offset;
  957. /*!
  958. \brief Offset of isles in sidx file
  959. */
  960. off_t Isle_spidx_offset;
  961. /*!
  962. \brief Offset of faces in sidx file
  963. */
  964. off_t Face_spidx_offset;
  965. /*!
  966. \brief Offset of volumes in sidx file
  967. */
  968. off_t Volume_spidx_offset;
  969. /*!
  970. \brief Offset of holes in sidx file
  971. */
  972. off_t Hole_spidx_offset;
  973. /*!
  974. \brief Node spatial index
  975. */
  976. struct RTree *Node_spidx;
  977. /*!
  978. \brief Line spatial index
  979. */
  980. struct RTree *Line_spidx;
  981. /*!
  982. \brief Area spatial index
  983. */
  984. struct RTree *Area_spidx;
  985. /*!
  986. \brief Isles spatial index
  987. */
  988. struct RTree *Isle_spidx;
  989. /*!
  990. \brief Faces spatial index
  991. */
  992. struct RTree *Face_spidx;
  993. /*!
  994. \brief Volumes spatial index
  995. */
  996. struct RTree *Volume_spidx;
  997. /*!
  998. \brief Holes spatial index
  999. */
  1000. struct RTree *Hole_spidx;
  1001. /*** category index ***/
  1002. /*!
  1003. \brief Update category index if vector is modified
  1004. By default, category index is not updated
  1005. */
  1006. int update_cidx;
  1007. /*!
  1008. \brief Number of category indexes (one for each field/layer)
  1009. */
  1010. int n_cidx;
  1011. /*!
  1012. \brief Allocated space for category indexes
  1013. */
  1014. int a_cidx;
  1015. /*!
  1016. \brief Array of category indexes
  1017. */
  1018. struct Cat_index *cidx;
  1019. /*!
  1020. \brief Category index to be updated
  1021. Set to 1 when cidx is created
  1022. and reset to 0 whenever any line is changed
  1023. */
  1024. int cidx_up_to_date;
  1025. /*!
  1026. \brief Size of coor file
  1027. */
  1028. off_t coor_size;
  1029. /*!
  1030. \brief Time of last coor modification
  1031. */
  1032. long coor_mtime;
  1033. /*** level 2 ***/
  1034. /*!
  1035. \brief List of updated lines/nodes
  1036. Note: Vect_set_updated() must be called to maintain this list
  1037. */
  1038. struct {
  1039. /*!
  1040. \brief Indicates if the list of updated features is maintained
  1041. */
  1042. int do_uplist;
  1043. /*!
  1044. \brief Array of updated lines
  1045. List of lines and nodes updated (topo info for the line was
  1046. changed) by last write/rewrite/delete operation.
  1047. Lines/nodes in the list may be deleted (e.g. delete
  1048. boundary: first added for delete area and then delete
  1049. */
  1050. int *uplines;
  1051. /*!
  1052. \brief Array of updated lines - offset
  1053. Negative value for dead (deleted) lines - used by Vect_restore_line()
  1054. */
  1055. off_t *uplines_offset;
  1056. /*!
  1057. \brief Allocated array of lines
  1058. */
  1059. int alloc_uplines;
  1060. /*!
  1061. \brief Number of updated lines
  1062. */
  1063. int n_uplines;
  1064. /*!
  1065. \brief Array of updated nodes
  1066. */
  1067. int *upnodes;
  1068. /*!
  1069. \brief Allocated array of nodes
  1070. */
  1071. int alloc_upnodes;
  1072. /*!
  1073. \brief number of updated nodes
  1074. */
  1075. int n_upnodes;
  1076. } uplist;
  1077. };
  1078. /*!
  1079. \brief Graph-related section (see \ref dglib)
  1080. */
  1081. struct Graph_info {
  1082. /*!
  1083. \brief Line type used to build the graph
  1084. */
  1085. int line_type;
  1086. /*!
  1087. \brief Graph structure
  1088. */
  1089. dglGraph_s graph_s;
  1090. /*!
  1091. \brief Shortest path cache
  1092. */
  1093. dglSPCache_s spCache;
  1094. /*!
  1095. \brief Forward costs used for graph
  1096. dglGetEdge() is not supported for _DGL_V1)
  1097. */
  1098. double *edge_fcosts;
  1099. /*!
  1100. \brief backward costs used for graph
  1101. */
  1102. double *edge_bcosts;
  1103. /*!
  1104. \brief Node costs used for graph
  1105. */
  1106. double *node_costs;
  1107. /*!
  1108. \brief Edge and node costs multiplicator
  1109. */
  1110. int cost_multip;
  1111. };
  1112. /*! \brief
  1113. Vector map info
  1114. Maintains all information about an individual open vector map. The
  1115. structure must be passed to the most vector library routines.
  1116. */
  1117. struct Map_info
  1118. {
  1119. /*** common info for all formats ***/
  1120. /*!
  1121. \brief Map format (native, ogr, postgis)
  1122. - GV_FORMAT_NATIVE
  1123. - GV_FORMAT_OGR
  1124. - GV_FORMAT_OGR_DIRECT
  1125. - GV_FORMAT_POSTGIS
  1126. */
  1127. int format;
  1128. /*!
  1129. \brief Temporary map flag
  1130. */
  1131. int temporary;
  1132. /*!
  1133. \brief Array of DB links
  1134. */
  1135. struct dblinks *dblnk;
  1136. /*!
  1137. \brief Plus info (topology, version, ...)
  1138. */
  1139. struct Plus_head plus;
  1140. /*!
  1141. \brief Open indicator
  1142. Should be 0x5522AA22 (VECT_OPEN_CODE) if opened correctly
  1143. or 0x22AA2255 (VECT_CLOSED_CODE) if closed
  1144. Anything else implies that structure has never been initialized
  1145. */
  1146. int open;
  1147. /* Open mode
  1148. - read (GV_MODE_READ),
  1149. - write (GV_MODE_WRITE),
  1150. - rw (GV_MODE_RW)
  1151. */
  1152. int mode;
  1153. /*!
  1154. \brief Topology level
  1155. - 1 (without topo)
  1156. - 2 (with 2D topology)
  1157. - 3 (with 3D topology) - not yet implemented
  1158. */
  1159. int level;
  1160. /*!
  1161. \brief Open only header
  1162. Non-zero code to open only header of vector map
  1163. */
  1164. int head_only;
  1165. /*!
  1166. \brief Support files were updated
  1167. Non-zero code to indicate that supoort file were updated
  1168. */
  1169. int support_updated;
  1170. /*!
  1171. \brief Map name (for 4.0)
  1172. */
  1173. char *name;
  1174. /*!
  1175. \brief Mapset name
  1176. */
  1177. char *mapset;
  1178. /*!
  1179. \brief Location name
  1180. Note: location and gisdbase is useful if changed (v.proj or external apps)
  1181. */
  1182. char *location;
  1183. /*!
  1184. \brief GISDBASE path
  1185. */
  1186. char *gisdbase;
  1187. /*!
  1188. \brief Feature id for sequential access
  1189. Note: Line id starts with 1 - see Vect_read_next_line()
  1190. */
  1191. plus_t next_line;
  1192. /*!
  1193. \brief Constraints for sequential feature access
  1194. */
  1195. struct {
  1196. /*!
  1197. \brief Non-zero value to enable region constraint
  1198. */
  1199. int region_flag;
  1200. /*!
  1201. \brief Region (bbox) constraint
  1202. */
  1203. struct bound_box box;
  1204. /*!
  1205. \brief Non-zero value to enable feature type constraint
  1206. */
  1207. int type_flag;
  1208. /*!
  1209. \brief Feature type constraint
  1210. */
  1211. int type;
  1212. /*!
  1213. \brief Non-zero value to enable field constraint
  1214. */
  1215. int field_flag;
  1216. /*!
  1217. \brief Field number constraint (see line_cats structure)
  1218. */
  1219. int field;
  1220. } constraint;
  1221. /*!
  1222. \brief ???
  1223. */
  1224. int proj;
  1225. /*!
  1226. \brief History file
  1227. */
  1228. FILE *hist_fp;
  1229. /*!
  1230. \brief Graph info (built for network analysis)
  1231. */
  1232. struct Graph_info dgraph;
  1233. /*!
  1234. \brief Header info
  1235. */
  1236. struct dig_head head;
  1237. /*** format specific ***/
  1238. /*!
  1239. \brief GV file pointer (native format only)
  1240. */
  1241. struct gvfile dig_fp;
  1242. /*!
  1243. \brief Format info for non-native formats
  1244. */
  1245. struct Format_info fInfo;
  1246. /* temporary solution for sites - to be removed ?*/
  1247. /*!
  1248. \brief Array of attributes loaded from db
  1249. \todo To be removed?
  1250. */
  1251. struct site_att *site_att;
  1252. /*!
  1253. \brief Number of attributes in site_att array
  1254. \todo To be removed?
  1255. */
  1256. int n_site_att;
  1257. /*!
  1258. \brief Number of double attributes for one site
  1259. \todo To be removed
  1260. */
  1261. int n_site_dbl;
  1262. /*!
  1263. \brief Number of string attributes for one site
  1264. \todo To be removed?
  1265. */
  1266. int n_site_str;
  1267. };
  1268. /*!
  1269. \brief Topological feature - node
  1270. */
  1271. struct P_node
  1272. {
  1273. /*!
  1274. \brief X coordinate
  1275. */
  1276. double x;
  1277. /*!
  1278. \brief Y coordinate
  1279. */
  1280. double y;
  1281. /*!
  1282. \brief Z coordinate (used only for 3D data)
  1283. */
  1284. double z;
  1285. /*!
  1286. \brief Allocated space for lines
  1287. */
  1288. plus_t alloc_lines;
  1289. /*!
  1290. \brief Number of attached lines (size of
  1291. lines, angle)
  1292. If 0, then is degenerate node, for snapping ???
  1293. */
  1294. plus_t n_lines;
  1295. /*!
  1296. \brief List of connected lines
  1297. Line id can be positive (for lines which starts at the node) or
  1298. negative (for lines which ends at the node).
  1299. */
  1300. plus_t *lines;
  1301. /*!
  1302. \brief List of angles of connected lines
  1303. Angles for lines/boundaries are in radians between -PI and
  1304. PI. Value for points or lines with identical points
  1305. (degenerated) is set to -9. See dig_calc_begin_angle() and
  1306. dig_calc_end_angle() for details.
  1307. */
  1308. float *angles;
  1309. };
  1310. /*!
  1311. \brief Line topology
  1312. */
  1313. struct P_topo_l
  1314. {
  1315. /*!
  1316. \brief Start node
  1317. */
  1318. plus_t N1;
  1319. /*!
  1320. \brief End node
  1321. */
  1322. plus_t N2;
  1323. };
  1324. /*!
  1325. \brief Boundary topology
  1326. */
  1327. struct P_topo_b
  1328. {
  1329. /*!
  1330. \brief Start node
  1331. */
  1332. plus_t N1;
  1333. /*!
  1334. \brief End node
  1335. */
  1336. plus_t N2;
  1337. /*!
  1338. \brief Area number to the left, negative for isle
  1339. */
  1340. plus_t left;
  1341. /*!
  1342. \brief Area number to the right, negative for isle
  1343. */
  1344. plus_t right;
  1345. };
  1346. /*!
  1347. \brief Centroid topology
  1348. */
  1349. struct P_topo_c
  1350. {
  1351. /*!
  1352. \brief Area number, negative for duplicate centroid
  1353. */
  1354. plus_t area;
  1355. };
  1356. /*!
  1357. \brief Face topology
  1358. */
  1359. struct P_topo_f
  1360. {
  1361. /* TODO */
  1362. /*!
  1363. \brief Array of edges
  1364. */
  1365. plus_t E[3];
  1366. /*!
  1367. \brief Volume number to the left, negative for hole
  1368. */
  1369. plus_t left;
  1370. /*!
  1371. \brief Volume number to the right, negative for hole
  1372. */
  1373. plus_t right;
  1374. };
  1375. /*!
  1376. \brief Kernel topology
  1377. */
  1378. struct P_topo_k
  1379. {
  1380. /*!
  1381. \brief Volume number, negative for duplicate kernel
  1382. */
  1383. plus_t volume;
  1384. };
  1385. /*!
  1386. \brief Vector geometry
  1387. */
  1388. struct P_line
  1389. {
  1390. /*!
  1391. \brief Line type
  1392. - GV_POINT
  1393. - GV_LINE
  1394. - GV_BOUNDARY
  1395. - GV_CENTROID
  1396. - GV_FACE
  1397. - GV_KERNEL
  1398. */
  1399. char type;
  1400. /*!
  1401. \brief Offset in coor file for line
  1402. OGR-links: offset array index
  1403. PG-links: node/edge id
  1404. */
  1405. off_t offset;
  1406. /*!
  1407. \brief Topology info
  1408. NULL for points
  1409. */
  1410. void *topo;
  1411. };
  1412. /*!
  1413. \brief Area (topology) info
  1414. */
  1415. struct P_area
  1416. {
  1417. /*!
  1418. \brief Number of boundary lines
  1419. */
  1420. plus_t n_lines;
  1421. /*!
  1422. \brief Allocated space for lines
  1423. */
  1424. plus_t alloc_lines;
  1425. /*!
  1426. \brief List of boundary lines
  1427. - negative means direction N2 to N1
  1428. - lines are in clockwise order
  1429. */
  1430. plus_t *lines;
  1431. /********* Above this line is compatible with P_isle **********/
  1432. /*!
  1433. \brief Number of first centroid within area
  1434. */
  1435. plus_t centroid;
  1436. /*!
  1437. \brief Number of islands inside
  1438. */
  1439. plus_t n_isles;
  1440. /*!
  1441. \brief Allocated space for isles
  1442. */
  1443. plus_t alloc_isles;
  1444. /*!
  1445. \brief 1st generation interior islands
  1446. */
  1447. plus_t *isles;
  1448. };
  1449. /*!
  1450. \brief Isle (topology) info
  1451. */
  1452. struct P_isle
  1453. {
  1454. /*!
  1455. \brief Number of boundary lines
  1456. */
  1457. plus_t n_lines;
  1458. /*!
  1459. \brief Allocated space for lines
  1460. */
  1461. plus_t alloc_lines;
  1462. /*!
  1463. \brief List of boundary lines
  1464. - negative means direction N2 to N1
  1465. - lines are in counter clockwise order
  1466. */
  1467. plus_t *lines;
  1468. /********* Above this line is compatible with P_area **********/
  1469. /*!
  1470. \brief Area it exists w/in, if any
  1471. */
  1472. plus_t area;
  1473. };
  1474. /*!
  1475. \brief Feature geometry info - coordinates
  1476. */
  1477. struct line_pnts
  1478. {
  1479. /*!
  1480. \brief Array of X coordinates
  1481. */
  1482. double *x;
  1483. /*!
  1484. \brief Array of Y coordinates
  1485. */
  1486. double *y;
  1487. /*!
  1488. \brief Array of Z coordinates
  1489. */
  1490. double *z;
  1491. /*!
  1492. \brief Number of points
  1493. */
  1494. int n_points;
  1495. /*!
  1496. \brief Allocated space for points
  1497. */
  1498. int alloc_points;
  1499. };
  1500. /*!
  1501. \brief Feature category info
  1502. */
  1503. struct line_cats
  1504. {
  1505. /*!
  1506. \brief Array of layers (fields)
  1507. */
  1508. int *field;
  1509. /*!
  1510. \brief Array of categories
  1511. */
  1512. int *cat;
  1513. /*!
  1514. \brief Number of categories attached to element
  1515. */
  1516. int n_cats;
  1517. /*!
  1518. \brief Allocated space for categories
  1519. */
  1520. int alloc_cats;
  1521. };
  1522. /*! \brief Category list */
  1523. struct cat_list
  1524. {
  1525. /*!
  1526. \brief Category layer (field)
  1527. */
  1528. int field;
  1529. /*!
  1530. \brief Array of minimum values
  1531. */
  1532. int *min;
  1533. /*!
  1534. \brief Array of maximum values
  1535. */
  1536. int *max;
  1537. /*!
  1538. \brief Number of ranges
  1539. */
  1540. int n_ranges;
  1541. /*!
  1542. \brief Allocated space for ranges
  1543. */
  1544. int alloc_ranges;
  1545. };
  1546. /*!
  1547. \brief List of bounding boxes with id
  1548. */
  1549. struct boxlist
  1550. {
  1551. /*!
  1552. \brief Array of ids
  1553. */
  1554. int *id;
  1555. /*!
  1556. \brief Array of bounding boxes
  1557. */
  1558. struct bound_box *box;
  1559. /*!
  1560. \brief flag to indicate whether bounding boxes should be added
  1561. */
  1562. int have_boxes;
  1563. /*!
  1564. \brief Number of items in the list
  1565. */
  1566. int n_values;
  1567. /*!
  1568. \brief Allocated space for items
  1569. */
  1570. int alloc_values;
  1571. };
  1572. /*!
  1573. \brief Vector array
  1574. Space allocated is size + 1
  1575. */
  1576. struct varray
  1577. {
  1578. /*!
  1579. \brief Array size
  1580. */
  1581. int size;
  1582. /*!
  1583. \brief Array
  1584. Where 'class' or new category
  1585. or something like that is stored
  1586. */
  1587. int *c;
  1588. };
  1589. /*!
  1590. \brief Spatial index info
  1591. For use in modules
  1592. */
  1593. struct spatial_index
  1594. {
  1595. /*!
  1596. \brief Pointer to the search tree (R*-Tree)
  1597. */
  1598. struct RTree *si_tree;
  1599. /*!
  1600. \brief Name of file to store the search tree
  1601. */
  1602. char *name;
  1603. };
  1604. #endif /* DIG___STRUCTS___ */