SpatiaLite  4.0.0-RC1
 All Data Structures Files Functions Variables Typedefs Macros Pages
gg_structs.h
Go to the documentation of this file.
1 /*
2  gg_structs.h -- Gaia common support for geometries: structures
3 
4  version 4.0, 2012 August 6
5 
6  Author: Sandro Furieri a.furieri@lqt.it
7 
8  ------------------------------------------------------------------------------
9 
10  Version: MPL 1.1/GPL 2.0/LGPL 2.1
11 
12  The contents of this file are subject to the Mozilla Public License Version
13  1.1 (the "License"); you may not use this file except in compliance with
14  the License. You may obtain a copy of the License at
15  http://www.mozilla.org/MPL/
16 
17 Software distributed under the License is distributed on an "AS IS" basis,
18 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
19 for the specific language governing rights and limitations under the
20 License.
21 
22 The Original Code is the SpatiaLite library
23 
24 The Initial Developer of the Original Code is Alessandro Furieri
25 
26 Portions created by the Initial Developer are Copyright (C) 2008-2012
27 the Initial Developer. All Rights Reserved.
28 
29 Contributor(s):
30 
31 
32 Alternatively, the contents of this file may be used under the terms of
33 either the GNU General Public License Version 2 or later (the "GPL"), or
34 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
35 in which case the provisions of the GPL or the LGPL are applicable instead
36 of those above. If you wish to allow use of your version of this file only
37 under the terms of either the GPL or the LGPL, and not to allow others to
38 use your version of this file under the terms of the MPL, indicate your
39 decision by deleting the provisions above and replace them with the notice
40 and other provisions required by the GPL or the LGPL. If you do not delete
41 the provisions above, a recipient may use your version of this file under
42 the terms of any one of the MPL, the GPL or the LGPL.
43 
44 */
45 
46 
53 #ifndef _GG_STRUCTS_H
54 #ifndef DOXYGEN_SHOULD_SKIP_THIS
55 #define _GG_STRUCTS_H
56 #endif
57 
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
66  typedef struct gaiaPointStruct
67  {
68 /* an OpenGis POINT */
70  double X; /* X,Y coordinates */
72  double Y;
74  double Z; /* Z coordinate */
76  double M; /* M measure */
78  int DimensionModel; /* (x,y), (x,y,z), (x,y,m) or (x,y,z,m) */
80  struct gaiaPointStruct *Next; /* for double-linked list */
82  struct gaiaPointStruct *Prev; /* for double-linked list */
83  } gaiaPoint;
90 
94  typedef struct gaiaDynamicLineStruct
95  {
96 /* a generic DYNAMIC LINE object */
98  int Error;
100  int Srid;
102  gaiaPointPtr First; /* Points linked list - first */
104  gaiaPointPtr Last; /* Points linked list - last */
105  } gaiaDynamicLine;
112 
116  typedef struct gaiaLinestringStruct
117  {
118 /* an OpenGis LINESTRING */
120  int Points; /* number of vertices */
122  double *Coords; /* X,Y [vertices] array */
124  double MinX; /* MBR - BBOX */
126  double MinY; /* MBR - BBOX */
128  double MaxX; /* MBR - BBOX */
130  double MaxY; /* MBR - BBOX */
132  int DimensionModel; /* (x,y), (x,y,z), (x,y,m) or (x,y,z,m) */
134  struct gaiaLinestringStruct *Next; /* for linked list */
135  } gaiaLinestring;
142 
146  typedef struct gaiaRingStruct
147  {
148 /* a GIS ring - OpenGis LINESTRING, closed */
150  int Points; /* number of vertices */
152  double *Coords; /* X,Y [vertices] array */
154  int Clockwise; /* clockwise / counterclockwise */
156  double MinX; /* MBR - BBOX */
158  double MinY; /* MBR - BBOX */
160  double MaxX; /* MBR - BBOX */
162  double MaxY; /* MBR - BBOX */
164  int DimensionModel; /* (x,y), (x,y,z), (x,y,m) or (x,y,z,m) */
166  struct gaiaRingStruct *Next; /* for linked list */
168  struct gaiaPolygonStruct *Link; /* polygon reference */
169  } gaiaRing;
176 
180  typedef struct gaiaPolygonStruct
181  {
182 /* an OpenGis POLYGON */
184  gaiaRingPtr Exterior; /* exterior ring */
186  int NumInteriors; /* number of interior rings */
188  gaiaRingPtr Interiors; /* interior rings array */
190  int NextInterior; /* first free interior ring */
192  double MinX; /* MBR - BBOX */
194  double MinY; /* MBR - BBOX */
196  double MaxX; /* MBR - BBOX */
198  double MaxY; /* MBR - BBOX */
200  int DimensionModel; /* (x,y), (x,y,z), (x,y,m) or (x,y,z,m) */
202  struct gaiaPolygonStruct *Next; /* for linked list */
203  } gaiaPolygon;
210 
214  typedef struct gaiaGeomCollStruct
215  {
216 /* OpenGis GEOMETRYCOLLECTION */
218  int Srid; /* the SRID value for this GEOMETRY */
220  char endian_arch; /* littleEndian - bigEndian arch for target CPU */
222  char endian; /* littleEndian - bigEndian */
224  const unsigned char *blob; /* WKB encoded buffer */
226  unsigned long size; /* buffer size */
228  unsigned long offset; /* current offset [for parsing] */
230  gaiaPointPtr FirstPoint; /* Points linked list - first */
232  gaiaPointPtr LastPoint; /* Points linked list - last */
234  gaiaLinestringPtr FirstLinestring; /* Linestrings linked list - first */
236  gaiaLinestringPtr LastLinestring; /* Linestrings linked list - last */
238  gaiaPolygonPtr FirstPolygon; /* Polygons linked list - first */
240  gaiaPolygonPtr LastPolygon; /* Polygons linked list - last */
242  double MinX; /* MBR - BBOX */
244  double MinY; /* MBR - BBOX */
246  double MaxX; /* MBR - BBOX */
248  double MaxY; /* MBR - BBOX */
250  int DimensionModel; /* (x,y), (x,y,z), (x,y,m) or (x,y,z,m) */
252  int DeclaredType; /* the declared TYPE for this Geometry */
254  struct gaiaGeomCollStruct *Next; /* Vanuatu - used for linked list */
255  } gaiaGeomColl;
262 
266  typedef struct gaiaPreRingStruct
267  {
268 /* a LINESTRING used to build rings */
270  gaiaLinestringPtr Line; /* a LINESTRING pointer */
272  int AlreadyUsed; /* a switch to mark an already used line element */
274  struct gaiaPreRingStruct *Next; /* for linked list */
275  } gaiaPreRing;
282 
286  typedef struct gaiaValueStruct
287  {
288 /* a DBF field multitype value */
290  short Type; /* the type */
292  char *TxtValue; /* the text value */
294  sqlite3_int64 IntValue; /* the integer value */
296  double DblValue; /* the double value */
297  } gaiaValue;
302 
306  typedef struct gaiaDbfFieldStruct
307  {
308 /* a DBF field definition - shapefile attribute */
310  char *Name; /* field name */
312  unsigned char Type; /* field type */
314  int Offset; /* buffer offset [this field begins at *buffer+offset* and extends for *length* bytes */
316  unsigned char Length; /* field total length [in bytes] */
318  unsigned char Decimals; /* decimal positions */
320  gaiaValuePtr Value; /* the current multitype value for this attribute */
322  struct gaiaDbfFieldStruct *Next; /* pointer to next element in linked list */
323  } gaiaDbfField;
328 
332  typedef struct gaiaDbfListStruct
333  {
334 /* a linked list to contain the DBF fields definitions - shapefile attributes */
336  int RowId; /* the current RowId */
338  gaiaGeomCollPtr Geometry; /* geometry for current entity */
340  gaiaDbfFieldPtr First; /* pointer to first element in linked list */
342  gaiaDbfFieldPtr Last; /* pointer to last element in linker list */
343  } gaiaDbfList;
350 
354  typedef struct gaiaDbfStruct
355  {
356 /* DBF TYPE */
360  int Valid; /* 1 = ready to process */
362  char *Path; /* the DBF path */
364  FILE *flDbf; /* the DBF file handle */
366  gaiaDbfListPtr Dbf; /* the DBF attributes list */
368  unsigned char *BufDbf; /* the DBF I/O buffer */
370  int DbfHdsz; /* the DBF header length */
372  int DbfReclen; /* the DBF record length */
374  int DbfSize; /* current DBF size */
376  int DbfRecno; /* current DBF record number */
378  void *IconvObj; /* opaque reference to ICONV converter */
380  char *LastError; /* last error message */
381  } gaiaDbf;
387  typedef gaiaDbf *gaiaDbfPtr;
388 
392  typedef struct gaiaShapefileStruct
393  {
394 /* SHAPEFILE TYPE */
398  int Valid; /* 1 = ready to process */
400  int ReadOnly; /* read or write mode */
402  char *Path; /* the shapefile abstract path [no suffixes] */
404  FILE *flShx; /* the SHX file handle */
406  FILE *flShp; /* the SHP file handle */
408  FILE *flDbf; /* the DBF file handle */
410  int Shape; /* the SHAPE code for the whole shapefile */
412  gaiaDbfListPtr Dbf; /* the DBF attributes list */
414  unsigned char *BufDbf; /* the DBF I/O buffer */
416  int DbfHdsz; /* the DBF header length */
418  int DbfReclen; /* the DBF record length */
420  int DbfSize; /* current DBF size */
422  int DbfRecno; /* current DBF record number */
424  unsigned char *BufShp; /* the SHP I/O buffer */
426  int ShpBfsz; /* the SHP buffer current size */
428  int ShpSize; /* current SHP size */
430  int ShxSize; /* current SHX size */
432  double MinX; /* the MBR/BBOX for the whole shapefile */
434  double MinY;
436  double MaxX;
438  double MaxY;
440  void *IconvObj; /* opaque reference to ICONV converter */
442  char *LastError; /* last error message */
444  int EffectiveType; /* the effective Geometry-type, as determined by gaiaShpAnalyze() */
446  int EffectiveDims; /* the effective Dimensions [XY, XYZ, XYM, XYZM], as determined by gaiaShpAnalyze() */
447  } gaiaShapefile;
454 
458  typedef struct gaiaOutBufferStruct
459  {
460 /* a struct handling a dynamically growing output buffer */
462  char *Buffer;
468  int Error;
469  } gaiaOutBuffer;
476 
477 #ifndef OMIT_ICONV /* ICONV enabled: supporting text reader */
478 
480 #define VRTTXT_FIELDS_MAX 65535
481 
482 #define VRTTXT_BLOCK_MAX 65535
483 
485 #define VRTTXT_TEXT 1
486 
487 #define VRTTXT_INTEGER 2
488 
489 #define VRTTXT_DOUBLE 3
490 
491 #define VRTTXT_NULL 4
492 
496  struct vrttxt_line
497  {
498 /* a struct representing a full LINE (aka Record) */
500  off_t offset;
502  int len;
508  int error;
509  };
510 
514  struct vrttxt_row
515  {
516 /* a struct storing Row offsets */
518  int line_no;
520  off_t offset;
522  int len;
525  };
526 
531  {
532 /*
533 / for efficiency sake, individual Row offsets
534 / are grouped in reasonably sized blocks
535 */
539  int num_rows;
546  };
547 
552  {
553 /* a struct representing a Column (aka Field) header */
555  char *name;
557  int type;
558  };
559 
563  typedef struct vrttxt_reader
564  {
565 /* the main TXT-Reader struct */
569  FILE *text_file;
571  void *toUtf8; /* the UTF-8 ICONV converter */
581  int error;
587  struct vrttxt_row **rows;
589  int num_rows;
591  int line_no;
599  char *line_buffer;
610  } gaiaTextReader;
617 
618 #endif /* end ICONV (text reader) */
619 
620 #ifdef __cplusplus
621 }
622 #endif
623 
624 #endif /* _GG_STRUCTS_H */