2
\file include/vect/dig_structs.h
4
\brief Data structures for \ref vectorlib
6
\author Written by Dave Gerdes (CERL) 5/1988
7
\author Updated to GRASS 5.7 by Radim Blazek (2001)
8
\author Updated to GRASS 7.0 by Markus Metz (2011)
9
\author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
11
#include <grass/config.h>
13
#ifndef DIG___STRUCTS___
14
#define DIG___STRUCTS___
18
#include <sys/types.h>
20
#include <grass/dgl.h>
21
#include <grass/shapefil.h>
22
#include <grass/rbtree.h>
23
#include <grass/rtree.h>
24
#include <grass/dbmi.h>
37
3.10 changes plus_t to int. This assumes that any reasonable machine
38
will use 4 bytes to store an int. The diglib code is not guaranteed
39
to work if plus_t is changed to a type that is larger than an int.
44
\brief Used by sites lib
49
\brief Category number
53
\brief Array of double attributes
57
\brief Array of string attributes
94
\brief File definition
99
\brief File descriptor
103
\brief Pointer to beginning of the file in the memory
107
\brief Current position set by dig_seek()
111
\brief End of file in the memory (pointer to first byte after)
115
\brief Size of the file loaded to memory
119
\brief Allocated space
123
\brief Is file loaded?
132
\brief Layer (old: field) information
141
\brief Layer name (optional)
145
\brief Name of DB driver ('sqlite', 'dbf', ...)
149
brief Name of database
153
\brief Name of DB table
157
\brief Name of key column (usualy 'cat')
163
\brief Database links
168
\brief Pointer to the first field_info structure
170
struct field_info *field;
172
\brief Number of allocated slots
176
\brief Number of available layers (old: fields)
182
\brief Portability info
184
Set by V1_open_new() or V1_open_old()
189
\brief File byte order
193
\brief Size of `off_t` data type
198
\brief Conversion matrices between file and native byte order (double)
200
unsigned char dbl_cnvrt[PORT_DOUBLE];
202
\brief Conversion matrices between file and native byte order (float)
204
unsigned char flt_cnvrt[PORT_FLOAT];
206
\brief Conversion matrices between file and native byte order (long)
208
unsigned char lng_cnvrt[PORT_LONG];
210
\brief Conversion matrices between file and native byte order (int)
212
unsigned char int_cnvrt[PORT_INT];
214
\brief Conversion matrices between file and native byte order (short)
216
unsigned char shrt_cnvrt[PORT_SHORT];
218
\brief Conversion matrices between file and native byte order (off_t)
220
unsigned char off_t_cnvrt[PORT_OFF_T];
222
\brief Quick reading flag for double
224
Specify if native byte order of that type is the same
225
as byte order of vector file (TRUE) or not (FALSE)
229
\brief Quick reading flag for float
231
Specify if native byte order of that type is the same
232
as byte order of vector file (TRUE) or not (FALSE)
236
\brief Quick reading flag for long
238
Specify if native byte order of that type is the same
239
as byte order of vector file (TRUE) or not (FALSE)
243
\brief Quick reading flag for int
245
Specify if native byte order of that type is the same
246
as byte order of vector file (TRUE) or not (FALSE)
250
\brief Quick reading flag for short
252
Specify if native byte order of that type is the same
253
as byte order of vector file (TRUE) or not (FALSE)
257
\brief Quick reading flag for off_t
259
Specify if native byte order of that type is the same
260
as byte order of vector file (TRUE) or not (FALSE)
266
\brief List of dead lines in the file
270
The space can be reused, not yet used
277
/*! \brief Backward compatibility version info */
278
struct Version_info {
279
/*! \brief Current version (major) */
281
/*! \brief Current version (minor) */
283
/*! \brief Earliest version that can use this data format (major) */
285
/*! \brief Earliest version that can use this data format (minor) */
290
\brief Vector map header data
292
Holds header data of vector map (see \ref vlibMap_info)
297
\brief Organization name
317
\brief Original scale
324
int proj; /* projection */
327
\brief Zone (UTM only)
331
\brief Threshold for digitization
335
/* Programmers should NOT touch any thing below here */
336
/* Library takes care of everything for you */
338
/*! \brief Version info for coor file */
339
struct Version_info coor_version;
342
\brief 2D/3D vector data
345
- non-zero for 3D data
350
\brief Coor file size
354
\brief Coor header size
359
\brief Portability information
361
struct Port_info port;
364
\brief Offset of last read line
369
\brief Recycle dead line
371
\todo Not implemented yet
373
struct recycle *recycle;
377
\brief Coor file info
382
\brief Total size (in bytes)
386
\brief Time of last modification
392
\brief Data structure used for building pseudo-topology
394
See Vect__build_sfa() (Format_info_ogr and Format_info_pg) for
395
implementation issues.
397
struct Format_info_offset
402
Array where feature/part info is stored for each feature in
403
GRASS. This is not used for GV_CENTROID. Because one feature may
404
contain more elements (geometry collection also recursively),
405
offset for one line may be stored in more records. First record
406
is FID, next records are part indexes if necessary.
410
5. ring in 3. polygon in 7. feature (multipolygon) of geometry
411
collection which has FID = 123 123 (feature 123: geometry
412
colletion) 6 (7. feature in geometry collection: multiPolygon) 2
413
(3. polygon) 4 (5. ring in the polygon)
415
Example 2: geometry collection FID '1' containing one point, one
416
linestring and one polygon
424
1 0 first part (point)
427
3 1 second part (linestring)
430
5 2 third part (polygon)
431
6 0 first ring of polygon
440
4 1 centroid read from topo (idx == FID)
442
In PostGIS Topology mode the offset array is used for mapping
448
\brief Number of items in offset list
452
\brief Space allocated for offset list
459
\brief Lines cache for reading feature (non-native formats)
461
struct Format_info_cache {
465
Some simple features require more allocated lines (eg. polygon
466
with more rings, multipoint, or geometrycollection)
468
Line cache is also used for PostGIS Topology to store single
469
topological element (ctype == CACHE_FEATURE) or all elements
470
from the map (ctype == CACHE_MAP) to avoid random access which
473
struct line_pnts **lines;
475
\brief List of line types (GV_POINT, GV_LINE, ...)
479
\brief List of line cats (used only for PostGIS Topology access)
483
\brief Number of allocated lines in cache
487
\brief Number of lines which forms current feature
491
\brief Next line to be read from cache
499
\brief Simple feature type (currently used only by PG format)
501
SF_FeatureType sf_type;
505
Currenly used only by PostGIS Topology which allows to cache the
506
whole map (CACHE_MAP) */
511
\brief Non-native format info (OGR)
513
\todo Structure size should not change depending on compilation I
516
struct Format_info_ogr
519
\brief OGR driver name
523
\brief OGR datasource name
527
\brief OGR layer name
532
\brief Pointer to OGRDriver
536
\brief Pointer to OGRDataSource
540
\brief Pointer to OGRLayer
550
\brief Open DB driver when writing attributes
552
This driver is open by V2_open_new_ogr() and closed by
558
\brief Array of OGR DSN options
562
\brief Array of OGR layer options
564
char **layer_options;
567
\brief Lines cache for reading feature
569
struct Format_info_cache cache;
572
\brief Cache to avoid repeated reading (level 2)
574
NULL if no feature is in cache
577
OGRFeatureH feature_cache;
583
\brief Offset list used for building pseudo-topology
585
struct Format_info_offset offset;
588
\brief Next line to be read
590
Used by V2_read_next_line_ogr()
596
\brief Non-native format info (PostGIS)
598
struct Format_info_pg
601
\brief Connection string
605
\brief Database name (derived from conninfo)
621
\brief Geometry column (simple feature access)
625
\brief Feature type (simple feature access)
627
SF_FeatureType feature_type;
629
\brief Coordinates dimension (2D or 3D)
633
\brief Spatial reference system id (see spatial_ref_sys
639
\brief Open DB driver when writing attributes
641
This driver is open by V2_open_new_pg() and closed by
645
struct field_info *fi;
648
\brief Start/Finish transaction
653
\brief PGconn object (generated by PQconnectdb)
668
\brief Next line to be read
673
\brief Lines cache for reading feature
675
struct Format_info_cache cache;
678
\brief Offset list used for building pseudo-topology (simple
681
struct Format_info_offset offset;
683
/* PostGIS topology support */
685
\brief TopoGeometry column (feature table)
687
char *topogeom_column;
689
\brief Topology schema name and id
691
char *toposchema_name;
694
\brief Topology format
696
TRUE to store only Topo-Geo data in DB otherwise GRASS-like
697
topology is also maintained in DB
703
\brief Non-native format info (currently only OGR is implemented)
714
struct Format_info_ogr ogr;
718
struct Format_info_pg pg;
722
\brief Category index
727
\brief Field (layer) number
731
\brief Number of items in cat array
735
\brief Allocated space in cat array
739
\brief Array of cats (cat, type, lines/area)
743
\brief Number of unique cats (not updated)
747
\brief Number of types in type
751
\brief Number of elements for each type
763
\brief Offset of the beginning of this index in cidx file
769
\brief Basic topology-related info
771
Holds basic topology-related information about vector map
773
Important note: you should NOT store non-topological information in
774
topological structures.
778
/*! \brief Backward compatibility version info */
780
/*! \brief Version info for topology file */
781
struct Version_info topo;
782
/*! \brief Version info for spatial index file */
783
struct Version_info spidx;
784
/*! \brief Version info for category index file */
785
struct Version_info cidx;
789
\brief 2D/3D vector data
796
\brief 2D/3D spatial index
806
Because Plus_head is available to all releveant
811
/*** file header size ***/
814
\brief Topo header size
818
\brief Spatial index header size
820
long spidx_head_size;
822
\brief Category index header size
827
\brief Release memory occupied by support structures
828
(topo, spatial, category)
832
/*** portability info */
835
\brief Portability information
837
struct Port_info port;
839
\brief Portability information for spatial index
841
struct Port_info spidx_port;
843
\brief Portability information for category index
845
struct Port_info cidx_port;
856
\brief Highest level of topology currently available
861
- GV_BUILD_ATTACH_ISLES
867
\brief Bounding box of features
869
struct bound_box box;
873
\brief Array of nodes
875
struct P_node **Node;
877
\brief Array of vector geometries
879
struct P_line **Line;
881
\brief Array of areas
883
struct P_area **Area;
885
\brief Array of isles
887
struct P_isle **Isle;
889
/* add here P_FACE, P_VOLUME, P_HOLE */
892
\brief Current number of points
896
\brief Current number of lines
900
\brief Current number of boundaries
904
\brief Current number of centroids
908
\brief Current number of faces
912
\brief Current number of kernels
916
\brief Current number of volume faces
920
\brief Current number of hole faces
925
\brief Current number of topological features derived from vector
929
\brief Current number of nodes
933
\brief Current number of edges
937
\brief Current number of lines
941
\brief Current number of areas
945
\brief Current number of isles
949
\brief Current number of faces
953
\brief Current number of volumes
957
\brief Current number of holes
962
\brief Number of allocated nodes
968
\brief Number of allocated edges
974
\brief Number of allocated lines
980
\brief Number of allocated areas
986
\brief Number of allocated isles
992
\brief Number of allocated faces
998
\brief Number of allocated volumes
1002
plus_t alloc_volumes;
1004
\brief Number of allocated holes
1011
\brief Offset of array of nodes in topo file
1015
\brief Offset of array of edges in topo file
1019
\brief Offset of array of vector geometries in topo file
1023
\brief Offset of array of areas in topo file
1027
\brief Offset of array of isles in topo file
1031
\brief Offset of array of volumes in topo file
1033
off_t Volume_offset;
1035
\brief Offset of array of holes in topo file
1039
/*** spatial index ***/
1041
\brief Spatial index built?
1043
Set to 1 if spatial index is available
1047
\brief Build new spatial index
1049
Set to 1 if new spatial index will be generated
1053
\brief Build new spatial index in file
1055
Set to 1 to build new indices in file
1060
\brief Spatial index file pointer
1062
struct gvfile spidx_fp;
1065
\brief Offset of nodes in sidx file
1067
off_t Node_spidx_offset;
1069
\brief Offset of lines in sidx file
1071
off_t Line_spidx_offset;
1073
\brief Offset of areas in sidx file
1075
off_t Area_spidx_offset;
1077
\brief Offset of isles in sidx file
1079
off_t Isle_spidx_offset;
1081
\brief Offset of faces in sidx file
1083
off_t Face_spidx_offset;
1085
\brief Offset of volumes in sidx file
1087
off_t Volume_spidx_offset;
1089
\brief Offset of holes in sidx file
1091
off_t Hole_spidx_offset;
1094
\brief Node spatial index
1096
struct RTree *Node_spidx;
1098
\brief Line spatial index
1100
struct RTree *Line_spidx;
1102
\brief Area spatial index
1104
struct RTree *Area_spidx;
1106
\brief Isles spatial index
1108
struct RTree *Isle_spidx;
1110
\brief Faces spatial index
1112
struct RTree *Face_spidx;
1114
\brief Volumes spatial index
1116
struct RTree *Volume_spidx;
1118
\brief Holes spatial index
1120
struct RTree *Hole_spidx;
1122
/*** category index ***/
1124
\brief Update category index if vector is modified
1126
By default, category index is not updated
1131
\brief Number of category indexes (one for each field/layer)
1135
\brief Allocated space for category indexes
1139
\brief Array of category indexes
1141
struct Cat_index *cidx;
1143
\brief Category index to be updated
1145
Set to 1 when cidx is created
1146
and reset to 0 whenever any line is changed
1148
int cidx_up_to_date;
1151
\brief Size of coor file
1155
\brief Time of last coor modification
1161
\brief List of updated lines/nodes
1163
Note: Vect_set_updated() must be called to maintain this list
1167
\brief Indicates if the list of updated features is maintained
1172
\brief Array of updated lines
1174
List of lines and nodes updated (topo info for the line was
1175
changed) by last write/rewrite/delete operation.
1176
Lines/nodes in the list may be deleted (e.g. delete
1177
boundary: first added for delete area and then delete
1181
\brief Array of updated lines - offset
1183
Negative value for dead (deleted) lines - used by Vect_restore_line()
1185
off_t *uplines_offset;
1187
\brief Allocated array of lines
1191
\brief Number of updated lines
1195
\brief Array of updated nodes
1199
\brief Allocated array of nodes
1203
\brief number of updated nodes
1210
\brief Graph-related section (see \ref dglib)
1214
\brief Line type used to build the graph
1218
\brief Graph structure
1222
\brief Shortest path cache
1224
dglSPCache_s spCache;
1226
\brief Forward costs used for graph
1228
dglGetEdge() is not supported for _DGL_V1)
1230
double *edge_fcosts;
1232
\brief backward costs used for graph
1234
double *edge_bcosts;
1236
\brief Node costs used for graph
1240
\brief Edge and node costs multiplicator
1248
Maintains all information about an individual open vector map. The
1249
structure must be passed to the most vector library routines.
1253
/*** common info for all formats ***/
1256
\brief Map format (native, ogr, postgis)
1260
- GV_FORMAT_OGR_DIRECT
1266
\brief Temporary map flag
1271
\brief Array of DB links
1273
struct dblinks *dblnk;
1276
\brief Plus info (topology, version, ...)
1278
struct Plus_head plus;
1281
\brief Open indicator
1283
Should be 0x5522AA22 (VECT_OPEN_CODE) if opened correctly
1284
or 0x22AA2255 (VECT_CLOSED_CODE) if closed
1286
Anything else implies that structure has never been initialized
1292
- read (GV_MODE_READ),
1293
- write (GV_MODE_WRITE),
1299
\brief Topology level
1302
- 2 (with 2D topology)
1303
- 3 (with 3D topology) - not yet implemented
1308
\brief Open only header
1310
Non-zero code to open only header of vector map
1315
\brief Support files were updated
1317
Non-zero code to indicate that supoort file were updated
1319
int support_updated;
1322
\brief Map name (for 4.0)
1330
\brief Location name
1332
Note: location and gisdbase is useful if changed (v.proj or external apps)
1336
\brief GISDBASE path
1341
\brief Feature id for sequential access
1343
Note: Line id starts with 1 - see Vect_read_next_line()
1348
\brief Constraints for sequential feature access
1352
\brief Non-zero value to enable region constraint
1356
\brief Region (bbox) constraint
1358
struct bound_box box;
1360
\brief Non-zero value to enable feature type constraint
1364
\brief Feature type constraint
1368
\brief Non-zero value to enable field constraint
1372
\brief Field number constraint (see line_cats structure)
1388
\brief Graph info (built for network analysis)
1390
struct Graph_info dgraph;
1395
struct dig_head head;
1397
/*** format specific ***/
1400
\brief GV file pointer (native format only)
1402
struct gvfile dig_fp;
1405
\brief Format info for non-native formats
1407
struct Format_info fInfo;
1409
/* temporary solution for sites - to be removed ?*/
1412
\brief Array of attributes loaded from db
1414
\todo To be removed?
1416
struct site_att *site_att;
1418
\brief Number of attributes in site_att array
1420
\todo To be removed?
1424
\brief Number of double attributes for one site
1430
\brief Number of string attributes for one site
1432
\todo To be removed?
1438
\brief Topological feature - node
1451
\brief Z coordinate (used only for 3D data)
1455
\brief Allocated space for lines
1459
\brief Number of attached lines (size of
1462
If 0, then is degenerate node, for snapping ???
1466
\brief List of connected lines
1468
Line id can be positive (for lines which starts at the node) or
1469
negative (for lines which ends at the node).
1473
\brief List of angles of connected lines
1475
Angles for lines/boundaries are in radians between -PI and
1476
PI. Value for points or lines with identical points
1477
(degenerated) is set to -9. See dig_calc_begin_angle() and
1478
dig_calc_end_angle() for details.
1484
\brief Line topology
1499
\brief Boundary topology
1512
\brief Area number to the left, negative for isle
1516
\brief Area number to the right, negative for isle
1522
\brief Centroid topology
1527
\brief Area number, negative for duplicate centroid
1533
\brief Face topology
1539
\brief Array of edges
1543
\brief Volume number to the left, negative for hole
1547
\brief Volume number to the right, negative for hole
1553
\brief Kernel topology
1558
\brief Volume number, negative for duplicate kernel
1564
\brief Vector geometry
1580
\brief Offset in coor file for line
1582
OGR-links: offset array index
1583
PG-links: node/edge id
1587
\brief Topology info
1595
\brief Area (topology) info
1600
\brief Number of boundary lines
1604
\brief Allocated space for lines
1608
\brief List of boundary lines
1610
- negative means direction N2 to N1
1611
- lines are in clockwise order
1615
/********* Above this line is compatible with P_isle **********/
1618
\brief Number of first centroid within area
1622
\brief Number of islands inside
1626
\brief Allocated space for isles
1630
\brief 1st generation interior islands
1636
\brief Isle (topology) info
1641
\brief Number of boundary lines
1645
\brief Allocated space for lines
1649
\brief List of boundary lines
1651
- negative means direction N2 to N1
1652
- lines are in counter clockwise order
1656
/********* Above this line is compatible with P_area **********/
1659
\brief Area it exists w/in, if any
1665
\brief Feature geometry info - coordinates
1670
\brief Array of X coordinates
1674
\brief Array of Y coordinates
1678
\brief Array of Z coordinates
1682
\brief Number of points
1686
\brief Allocated space for points
1692
\brief Feature category info
1697
\brief Array of layers (fields)
1701
\brief Array of categories
1705
\brief Number of categories attached to element
1709
\brief Allocated space for categories
1714
/*! \brief Category list */
1718
\brief Category layer (field)
1722
\brief Array of minimum values
1726
\brief Array of maximum values
1730
\brief Number of ranges
1734
\brief Allocated space for ranges
1740
\brief List of bounding boxes with id
1749
\brief Array of bounding boxes
1751
struct bound_box *box;
1753
\brief flag to indicate whether bounding boxes should be added
1757
\brief Number of items in the list
1761
\brief Allocated space for items
1769
Space allocated is size + 1
1780
Where 'class' or new category
1781
or something like that is stored
1787
\brief Spatial index info
1791
struct spatial_index
1794
\brief Pointer to the search tree (R*-Tree)
1796
struct RTree *si_tree;
1798
\brief Name of file to store the search tree
1803
#endif /* DIG___STRUCTS___ */