-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeos.h
2558 lines (2336 loc) · 130 KB
/
meos.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************
*
* This MobilityDB code is provided under The PostgreSQL License.
* Copyright (c) 2016-2024, Université libre de Bruxelles and MobilityDB
* contributors
*
* MobilityDB includes portions of PostGIS version 3 source code released
* under the GNU General Public License (GPLv2 or later).
* Copyright (c) 2001-2024, PostGIS contributors
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without a written
* agreement is hereby granted, provided that the above copyright notice and
* this paragraph and the following two paragraphs appear in all copies.
*
* IN NO EVENT SHALL UNIVERSITE LIBRE DE BRUXELLES BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
* LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
* EVEN IF UNIVERSITE LIBRE DE BRUXELLES HAS BEEN ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* UNIVERSITE LIBRE DE BRUXELLES SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON
* AN "AS IS" BASIS, AND UNIVERSITE LIBRE DE BRUXELLES HAS NO OBLIGATIONS TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
*****************************************************************************/
/**
* @brief API of the Mobility Engine Open Source (MEOS) library.
*/
#ifndef __MEOS_H__
#define __MEOS_H__
/* C */
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
/* PostgreSQL */
#ifndef POSTGRES_H
#define POSTGRES_H
#define DatumGetPointer(X) ((Pointer) (X))
typedef char *Pointer;
typedef uintptr_t Datum;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef long int int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long int uint64;
typedef int32 DateADT;
typedef int64 TimeADT;
typedef int64 Timestamp;
typedef int64 TimestampTz;
typedef int64 TimeOffset;
typedef int32 fsec_t; /* fractional seconds (in microseconds) */
typedef struct
{
TimeOffset time; /* all time units other than days, months and years */
int32 day; /* days, after time for alignment */
int32 month; /* months and years, after time for alignment */
} Interval;
typedef struct varlena
{
char vl_len_[4]; /* Do not touch this field directly! */
char vl_dat[]; /* Data content is here */
} varlena;
typedef varlena text;
typedef struct varlena bytea;
#endif /* POSTGRES_H */
/* PostGIS */
#ifndef _LIBLWGEOM_H
#define _LIBLWGEOM_H
/******************************************************************/
/**
* Macros for manipulating the 'flags' byte. A uint8_t used as follows:
* VVSRGBMZ
* Version bit, followed by
* Validty, Solid, ReadOnly, Geodetic, HasBBox, HasM and HasZ flags.
*/
#define LWFLAG_Z 0x01
#define LWFLAG_M 0x02
#define LWFLAG_BBOX 0x04
#define LWFLAG_GEODETIC 0x08
#define LWFLAG_READONLY 0x10
#define LWFLAG_SOLID 0x20
#define FLAGS_GET_Z(flags) ((flags) & LWFLAG_Z)
#define FLAGS_GET_M(flags) (((flags) & LWFLAG_M)>>1)
#define FLAGS_GET_BBOX(flags) (((flags) & LWFLAG_BBOX)>>2)
#define FLAGS_GET_GEODETIC(flags) (((flags) & LWFLAG_GEODETIC)>>3)
#define FLAGS_GET_READONLY(flags) (((flags) & LWFLAG_READONLY)>>4)
#define FLAGS_GET_SOLID(flags) (((flags) & LWFLAG_SOLID)>>5)
#define FLAGS_SET_Z(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_Z) : ((flags) & ~LWFLAG_Z))
#define FLAGS_SET_M(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_M) : ((flags) & ~LWFLAG_M))
#define FLAGS_SET_BBOX(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_BBOX) : ((flags) & ~LWFLAG_BBOX))
#define FLAGS_SET_GEODETIC(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_GEODETIC) : ((flags) & ~LWFLAG_GEODETIC))
#define FLAGS_SET_READONLY(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_READONLY) : ((flags) & ~LWFLAG_READONLY))
#define FLAGS_SET_SOLID(flags, value) ((flags) = (value) ? ((flags) | LWFLAG_SOLID) : ((flags) & ~LWFLAG_SOLID))
#define FLAGS_NDIMS(flags) (2 + FLAGS_GET_Z(flags) + FLAGS_GET_M(flags))
#define FLAGS_GET_ZM(flags) (FLAGS_GET_M(flags) + FLAGS_GET_Z(flags) * 2)
#define FLAGS_NDIMS_BOX(flags) (FLAGS_GET_GEODETIC(flags) ? 3 : FLAGS_NDIMS(flags))
/*
** Variants available for WKB and WKT output types
*/
#define WKB_ISO 0x01
#define WKB_SFSQL 0x02
#define WKB_EXTENDED 0x04
#define WKB_NDR 0x08
#define WKB_XDR 0x10
#define WKB_HEX 0x20
#define WKB_NO_NPOINTS 0x40 /* Internal use only */
#define WKB_NO_SRID 0x80 /* Internal use only */
#define WKT_ISO 0x01
#define WKT_SFSQL 0x02
#define WKT_EXTENDED 0x04
typedef uint16_t lwflags_t;
/******************************************************************/
typedef struct {
double afac, bfac, cfac, dfac, efac, ffac, gfac, hfac, ifac, xoff, yoff, zoff;
} AFFINE;
/******************************************************************/
typedef struct
{
double xmin, ymin, zmin;
double xmax, ymax, zmax;
int32_t srid;
}
BOX3D;
/******************************************************************
* GBOX structure.
* We include the flags (information about dimensionality),
* so we don't have to constantly pass them
* into functions that use the GBOX.
*/
typedef struct
{
lwflags_t flags;
double xmin;
double xmax;
double ymin;
double ymax;
double zmin;
double zmax;
double mmin;
double mmax;
} GBOX;
/******************************************************************
* SPHEROID
*
* Standard definition of an ellipsoid (what wkt calls a spheroid)
* f = (a-b)/a
* e_sq = (a*a - b*b)/(a*a)
* b = a - fa
*/
typedef struct
{
double a; /* semimajor axis */
double b; /* semiminor axis b = (a - fa) */
double f; /* flattening f = (a-b)/a */
double e; /* eccentricity (first) */
double e_sq; /* eccentricity squared (first) e_sq = (a*a-b*b)/(a*a) */
double radius; /* spherical average radius = (2*a+b)/3 */
char name[20]; /* name of ellipse */
}
SPHEROID;
/******************************************************************
* POINT2D, POINT3D, POINT3DM, POINT4D
*/
typedef struct
{
double x, y;
}
POINT2D;
typedef struct
{
double x, y, z;
}
POINT3DZ;
typedef struct
{
double x, y, z;
}
POINT3D;
typedef struct
{
double x, y, m;
}
POINT3DM;
typedef struct
{
double x, y, z, m;
}
POINT4D;
/******************************************************************
* POINTARRAY
* Point array abstracts a lot of the complexity of points and point lists.
* It handles 2d/3d translation
* (2d points converted to 3d will have z=0 or NaN)
* DO NOT MIX 2D and 3D POINTS! EVERYTHING* is either one or the other
*/
typedef struct
{
uint32_t npoints; /* how many points we are currently storing */
uint32_t maxpoints; /* how many points we have space for in serialized_pointlist */
/* Use FLAGS_* macros to handle */
lwflags_t flags;
/* Array of POINT 2D, 3D or 4D, possibly misaligned. */
uint8_t *serialized_pointlist;
}
POINTARRAY;
/******************************************************************
* GSERIALIZED
*/
typedef struct
{
uint32_t size; /* For PgSQL use only, use VAR* macros to manipulate. */
uint8_t srid[3]; /* 24 bits of SRID */
uint8_t gflags; /* HasZ, HasM, HasBBox, IsGeodetic */
uint8_t data[1]; /* See gserialized.txt */
} GSERIALIZED;
/******************************************************************
* LWGEOM (any geometry type)
*
* Abstract type, note that 'type', 'bbox' and 'srid' are available in
* all geometry variants.
*/
typedef struct
{
GBOX *bbox;
void *data;
int32_t srid;
lwflags_t flags;
uint8_t type;
char pad[1]; /* Padding to 24 bytes (unused) */
}
LWGEOM;
/* POINTYPE */
typedef struct
{
GBOX *bbox;
POINTARRAY *point; /* hide 2d/3d (this will be an array of 1 point) */
int32_t srid;
lwflags_t flags;
uint8_t type; /* POINTTYPE */
char pad[1]; /* Padding to 24 bytes (unused) */
}
LWPOINT; /* "light-weight point" */
/* LINETYPE */
typedef struct
{
GBOX *bbox;
POINTARRAY *points; /* array of POINT3D */
int32_t srid;
lwflags_t flags;
uint8_t type; /* LINETYPE */
char pad[1]; /* Padding to 24 bytes (unused) */
}
LWLINE; /* "light-weight line" */
/* TRIANGLE */
typedef struct
{
GBOX *bbox;
POINTARRAY *points;
int32_t srid;
lwflags_t flags;
uint8_t type;
char pad[1]; /* Padding to 24 bytes (unused) */
}
LWTRIANGLE;
/* CIRCSTRINGTYPE */
typedef struct
{
GBOX *bbox;
POINTARRAY *points; /* array of POINT(3D/3DM) */
int32_t srid;
lwflags_t flags;
uint8_t type; /* CIRCSTRINGTYPE */
char pad[1]; /* Padding to 24 bytes (unused) */
}
LWCIRCSTRING; /* "light-weight circularstring" */
/* POLYGONTYPE */
typedef struct
{
GBOX *bbox;
POINTARRAY **rings; /* list of rings (list of points) */
int32_t srid;
lwflags_t flags;
uint8_t type; /* POLYGONTYPE */
char pad[1]; /* Padding to 24 bytes (unused) */
uint32_t nrings; /* how many rings we are currently storing */
uint32_t maxrings; /* how many rings we have space for in **rings */
}
LWPOLY; /* "light-weight polygon" */
/* MULTIPOINTTYPE */
typedef struct
{
GBOX *bbox;
LWPOINT **geoms;
int32_t srid;
lwflags_t flags;
uint8_t type; /* MULTYPOINTTYPE */
char pad[1]; /* Padding to 24 bytes (unused) */
uint32_t ngeoms; /* how many geometries we are currently storing */
uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
}
LWMPOINT;
/* MULTILINETYPE */
typedef struct
{
GBOX *bbox;
LWLINE **geoms;
int32_t srid;
lwflags_t flags;
uint8_t type; /* MULTILINETYPE */
char pad[1]; /* Padding to 24 bytes (unused) */
uint32_t ngeoms; /* how many geometries we are currently storing */
uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
}
LWMLINE;
/* MULTIPOLYGONTYPE */
typedef struct
{
GBOX *bbox;
LWPOLY **geoms;
int32_t srid;
lwflags_t flags;
uint8_t type; /* MULTIPOLYGONTYPE */
char pad[1]; /* Padding to 24 bytes (unused) */
uint32_t ngeoms; /* how many geometries we are currently storing */
uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
}
LWMPOLY;
/* COLLECTIONTYPE */
typedef struct
{
GBOX *bbox;
LWGEOM **geoms;
int32_t srid;
lwflags_t flags;
uint8_t type; /* COLLECTIONTYPE */
char pad[1]; /* Padding to 24 bytes (unused) */
uint32_t ngeoms; /* how many geometries we are currently storing */
uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
}
LWCOLLECTION;
/* COMPOUNDTYPE */
typedef struct
{
GBOX *bbox;
LWGEOM **geoms;
int32_t srid;
lwflags_t flags;
uint8_t type; /* COLLECTIONTYPE */
char pad[1]; /* Padding to 24 bytes (unused) */
uint32_t ngeoms; /* how many geometries we are currently storing */
uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
}
LWCOMPOUND; /* "light-weight compound line" */
/* CURVEPOLYTYPE */
typedef struct
{
GBOX *bbox;
LWGEOM **rings;
int32_t srid;
lwflags_t flags;
uint8_t type; /* CURVEPOLYTYPE */
char pad[1]; /* Padding to 24 bytes (unused) */
uint32_t nrings; /* how many rings we are currently storing */
uint32_t maxrings; /* how many rings we have space for in **rings */
}
LWCURVEPOLY; /* "light-weight polygon" */
/* MULTICURVE */
typedef struct
{
GBOX *bbox;
LWGEOM **geoms;
int32_t srid;
lwflags_t flags;
uint8_t type; /* MULTICURVE */
char pad[1]; /* Padding to 24 bytes (unused) */
uint32_t ngeoms; /* how many geometries we are currently storing */
uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
}
LWMCURVE;
/* MULTISURFACETYPE */
typedef struct
{
GBOX *bbox;
LWGEOM **geoms;
int32_t srid;
lwflags_t flags;
uint8_t type; /* MULTISURFACETYPE */
char pad[1]; /* Padding to 24 bytes (unused) */
uint32_t ngeoms; /* how many geometries we are currently storing */
uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
}
LWMSURFACE;
/* POLYHEDRALSURFACETYPE */
typedef struct
{
GBOX *bbox;
LWPOLY **geoms;
int32_t srid;
lwflags_t flags;
uint8_t type; /* POLYHEDRALSURFACETYPE */
char pad[1]; /* Padding to 24 bytes (unused) */
uint32_t ngeoms; /* how many geometries we are currently storing */
uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
}
LWPSURFACE;
/* TINTYPE */
typedef struct
{
GBOX *bbox;
LWTRIANGLE **geoms;
int32_t srid;
lwflags_t flags;
uint8_t type; /* TINTYPE */
char pad[1]; /* Padding to 24 bytes (unused) */
uint32_t ngeoms; /* how many geometries we are currently storing */
uint32_t maxgeoms; /* how many geometries we have space for in **geoms */
}
LWTIN;
/* Functions */
extern int32 geo_get_srid(const GSERIALIZED *g);
/* PROJ */
struct PJconsts;
typedef struct PJconsts PJ;
typedef struct LWPROJ
{
PJ* pj;
/* for pipeline transforms, whether to do a forward or inverse */
bool pipeline_is_forward;
/* Source crs is geographic: Used in geography calls (source srid == dst srid) */
uint8_t source_is_latlong;
/* Source ellipsoid parameters */
double source_semi_major_metre;
double source_semi_minor_metre;
} LWPROJ;
#endif /* _LIBLWGEOM_H */
/*****************************************************************************
* Toolchain dependent definitions
*****************************************************************************/
#ifdef _MSC_VER
/*
* Under MSVC, functions exported by a loadable module must be marked
* "dllexport". Other compilers don't need that.
* Borrowed from PostgreSQL file win32.h
*/
#define PGDLLEXPORT __declspec (dllexport)
/*
* Avoids warning C4996: 'strdup': The POSIX name for this item is deprecated.
*/
#define strdup _strdup
#endif
/*****************************************************************************
* Type definitions
*****************************************************************************/
/**
* @brief Align to double
*/
#define DOUBLE_PAD(size) ( (size) + ((size) % 8 ? (8 - (size) % 8) : 0 ) )
/**
* Structure to represent sets of values
*/
typedef struct
{
int32 vl_len_; /**< Varlena header (do not touch directly!) */
uint8 settype; /**< Set type */
uint8 basetype; /**< Span basetype */
int16 flags; /**< Flags */
int32 count; /**< Number of elements */
int32 maxcount; /**< Maximum number of elements */
int16 bboxsize; /**< Size of the bouding box */
} Set;
/**
* Structure to represent spans (a.k.a. ranges)
*/
typedef struct
{
uint8 spantype; /**< span type */
uint8 basetype; /**< span basetype */
bool lower_inc; /**< lower bound is inclusive (vs exclusive) */
bool upper_inc; /**< upper bound is inclusive (vs exclusive) */
char padding[4]; /**< Not used */
Datum lower; /**< lower bound value */
Datum upper; /**< upper bound value */
} Span;
/**
* Structure to represent span sets
*/
typedef struct
{
int32 vl_len_; /**< Varlena header (do not touch directly!) */
uint8 spansettype; /**< Span set type */
uint8 spantype; /**< Span type */
uint8 basetype; /**< Span basetype */
char padding; /**< Not used */
int32 count; /**< Number of elements */
int32 maxcount; /**< Maximum number of elements */
Span span; /**< Bounding span */
Span elems[1]; /**< Beginning of variable-length data */
} SpanSet;
/**
* Structure to represent temporal boxes
*/
typedef struct
{
Span period; /**< time span */
Span span; /**< value span */
int16 flags; /**< flags */
} TBox;
/**
* Structure to represent spatiotemporal boxes
*/
typedef struct
{
Span period; /**< time span */
double xmin; /**< minimum x value */
double ymin; /**< minimum y value */
double zmin; /**< minimum z value */
double xmax; /**< maximum x value */
double ymax; /**< maximum y value */
double zmax; /**< maximum z value */
int32 srid; /**< SRID */
int16 flags; /**< flags */
} STBox;
/**
* @brief Enumeration that defines the temporal subtypes used in MEOS
*/
typedef enum
{
ANYTEMPSUBTYPE = 0, /**< Any temporal subtype */
TINSTANT = 1, /**< Temporal instant subtype */
TSEQUENCE = 2, /**< Temporal sequence subtype */
TSEQUENCESET = 3, /**< Temporal sequence set subtype */
} tempSubtype;
/**
* @brief Enumeration that defines the interpolation types used in MEOS
*/
typedef enum
{
INTERP_NONE = 0,
DISCRETE = 1,
STEP = 2,
LINEAR = 3,
} interpType;
/**
* @brief Enumeration that defines the spatial relationships for which a call
* to GEOS is made.
*/
typedef enum
{
INTERSECTS = 0,
CONTAINS = 1,
TOUCHES = 2,
COVERS = 3,
} spatialRel;
/**
* Structure to represent the common structure of temporal values of
* any temporal subtype
*/
typedef struct
{
int32 vl_len_; /**< Varlena header (do not touch directly!) */
uint8 temptype; /**< Temporal type */
uint8 subtype; /**< Temporal subtype */
int16 flags; /**< Flags */
/* variable-length data follows */
} Temporal;
/**
* Structure to represent temporal values of instant subtype
*/
typedef struct
{
int32 vl_len_; /**< Varlena header (do not touch directly!) */
uint8 temptype; /**< Temporal type */
uint8 subtype; /**< Temporal subtype */
int16 flags; /**< Flags */
TimestampTz t; /**< Timestamp (8 bytes) */
Datum value; /**< Base value for types passed by value,
first 8 bytes of the base value for values
passed by reference. The extra bytes
needed are added upon creation. */
/* variable-length data follows */
} TInstant;
/**
* Structure to represent temporal values of instant set or sequence subtype
*/
typedef struct
{
int32 vl_len_; /**< Varlena header (do not touch directly!) */
uint8 temptype; /**< Temporal type */
uint8 subtype; /**< Temporal subtype */
int16 flags; /**< Flags */
int32 count; /**< Number of TInstant elements */
int32 maxcount; /**< Maximum number of TInstant elements */
int16 bboxsize; /**< Size of the bounding box */
char padding[6]; /**< Not used */
Span period; /**< Time span (24 bytes). All bounding boxes start
with a period so actually it is also the begining
of the bounding box. The extra bytes needed for
the bounding box are added upon creation. */
/* variable-length data follows */
} TSequence;
#define TSEQUENCE_BBOX_PTR(seq) ((void *)(&(seq)->period))
/**
* Structure to represent temporal values of sequence set subtype
*/
typedef struct
{
int32 vl_len_; /**< Varlena header (do not touch directly!) */
uint8 temptype; /**< Temporal type */
uint8 subtype; /**< Temporal subtype */
int16 flags; /**< Flags */
int32 count; /**< Number of TSequence elements */
int32 totalcount; /**< Total number of TInstant elements in all
composing TSequence elements */
int32 maxcount; /**< Maximum number of TSequence elements */
int16 bboxsize; /**< Size of the bounding box */
int16 padding; /**< Not used */
Span period; /**< Time span (24 bytes). All bounding boxes start
with a period so actually it is also the begining
of the bounding box. The extra bytes needed for
the bounding box are added upon creation. */
/* variable-length data follows */
} TSequenceSet;
#define TSEQUENCESET_BBOX_PTR(ss) ((void *)(&(ss)->period))
/**
* Struct for storing a similarity match
*/
typedef struct
{
int i;
int j;
} Match;
/*****************************************************************************/
/**
* Structure to represent skiplist elements
*/
#define SKIPLIST_MAXLEVEL 32 /**< maximum possible is 47 with current RNG */
typedef struct
{
void *value;
int height;
int next[SKIPLIST_MAXLEVEL];
} SkipListElem;
/**
* Structure to represent skiplists that keep the current state of an aggregation
*/
typedef struct
{
int capacity;
int next;
int length;
int *freed;
int freecount;
int freecap;
int tail;
void *extra;
size_t extrasize;
SkipListElem *elems;
} SkipList;
/*****************************************************************************
* Error codes
*****************************************************************************/
typedef enum
{
MEOS_SUCCESS = 0, // Successful operation
MEOS_ERR_INTERNAL_ERROR = 1, // Unspecified internal error
MEOS_ERR_INTERNAL_TYPE_ERROR = 2, // Internal type error
MEOS_ERR_VALUE_OUT_OF_RANGE = 3, // Internal out of range error
MEOS_ERR_DIVISION_BY_ZERO = 4, // Internal division by zero error
MEOS_ERR_MEMORY_ALLOC_ERROR = 5, // Internal malloc error
MEOS_ERR_AGGREGATION_ERROR = 6, // Internal aggregation error
MEOS_ERR_DIRECTORY_ERROR = 7, // Internal directory error
MEOS_ERR_FILE_ERROR = 8, // Internal file error
MEOS_ERR_INVALID_ARG = 10, // Invalid argument
MEOS_ERR_INVALID_ARG_TYPE = 11, // Invalid argument type
MEOS_ERR_INVALID_ARG_VALUE = 12, // Invalid argument value
MEOS_ERR_MFJSON_INPUT = 20, // MFJSON input error
MEOS_ERR_MFJSON_OUTPUT = 21, // MFJSON output error
MEOS_ERR_TEXT_INPUT = 22, // Text input error
MEOS_ERR_TEXT_OUTPUT = 23, // Text output error
MEOS_ERR_WKB_INPUT = 24, // WKB input error
MEOS_ERR_WKB_OUTPUT = 25, // WKB output error
MEOS_ERR_GEOJSON_INPUT = 26, // GEOJSON input error
MEOS_ERR_GEOJSON_OUTPUT = 27, // GEOJSON output error
} errorCode;
extern void meos_error(int errlevel, int errcode, char *format, ...);
/* Set or read error level */
extern int meos_errno(void);
extern int meos_errno_set(int err);
extern int meos_errno_restore(int err);
extern int meos_errno_reset(void);
/*****************************************************************************
* Initialization of the MEOS library
*****************************************************************************/
/* Definition of error handler function */
typedef void (*error_handler_fn)(int, int, char *);
extern void meos_initialize_timezone(const char *name);
extern void meos_initialize_error_handler(error_handler_fn err_handler);
extern void meos_finalize_timezone(void);
extern bool meos_set_datestyle(char *newval, void *extra);
extern bool meos_set_intervalstyle(char *newval, int extra);
extern char *meos_get_datestyle(void);
extern char *meos_get_intervalstyle(void);
extern void meos_initialize(const char *tz_str, error_handler_fn err_handler);
extern void meos_finalize(void);
/*===========================================================================*
* Functions for PostgreSQL types
*===========================================================================*/
extern DateADT add_date_int(DateADT d, int32 days);
extern Interval *add_interval_interval(const Interval *interv1, const Interval *interv2);
extern TimestampTz add_timestamptz_interval(TimestampTz t, const Interval *interv);
extern bool bool_in(const char *str);
extern char *bool_out(bool b);
extern text *cstring2text(const char *str);
extern TimestampTz date_to_timestamptz(DateADT d);
extern Interval *minus_date_date(DateADT d1, DateADT d2);
extern DateADT minus_date_int(DateADT d, int32 days);
extern TimestampTz minus_timestamptz_interval(TimestampTz t, const Interval *interv);
extern Interval *minus_timestamptz_timestamptz(TimestampTz t1, TimestampTz t2);
extern Interval *mult_interval_double(const Interval *interv, double factor);
extern DateADT pg_date_in(const char *str);
extern char *pg_date_out(DateADT d);
extern int pg_interval_cmp(const Interval *interv1, const Interval *interv2);
extern Interval *pg_interval_in(const char *str, int32 typmod);
extern Interval *pg_interval_make(int32 years, int32 months, int32 weeks, int32 days, int32 hours, int32 mins, double secs);
extern char *pg_interval_out(const Interval *interv);
extern TimeADT pg_time_in(const char *str, int32 typmod);
extern char *pg_time_out(TimeADT t);
extern Timestamp pg_timestamp_in(const char *str, int32 typmod);
extern char *pg_timestamp_out(Timestamp t);
extern TimestampTz pg_timestamptz_in(const char *str, int32 typmod);
extern char *pg_timestamptz_out(TimestampTz t);
extern char *text2cstring(const text *txt);
extern int text_cmp(const text *txt1, const text *txt2);
extern text *text_copy(const text *txt);
extern text *text_initcap(const text *txt);
extern text *text_lower(const text *txt);
extern char *text_out(const text *txt);
extern text *text_upper(const text *txt);
extern text *textcat_text_text(const text *txt1, const text *txt2);
extern DateADT timestamptz_to_date(TimestampTz t);
/*===========================================================================*
* Functions for PostGIS types
*===========================================================================*/
extern bytea *geo_as_ewkb(const GSERIALIZED *gs, char *endian);
extern char *geo_as_ewkt(const GSERIALIZED *gs, int precision);
extern char *geo_as_geojson(const GSERIALIZED *gs, int option, int precision, char *srs);
extern char *geo_as_hexewkb(const GSERIALIZED *gs, const char *endian);
extern char *geo_as_text(const GSERIALIZED *gs, int precision);
extern GSERIALIZED *geo_from_ewkb(const bytea *bytea_wkb, int32 srid);
extern GSERIALIZED *geo_from_geojson(const char *geojson);
extern char *geo_out(const GSERIALIZED *gs);
extern bool geo_same(const GSERIALIZED *gs1, const GSERIALIZED *gs2);
extern GSERIALIZED *geography_from_hexewkb(const char *wkt);
extern GSERIALIZED *geography_from_text(char *wkt, int srid);
extern GSERIALIZED *geometry_from_hexewkb(const char *wkt);
extern GSERIALIZED *geometry_from_text(char *wkt, int srid);
extern GSERIALIZED *pgis_geography_in(char *str, int32 typmod);
extern GSERIALIZED *pgis_geometry_in(char *str, int32 typmod);
/*===========================================================================*
* Functions for set and span types
*===========================================================================*/
/*****************************************************************************
* Input/output functions for set and span types
*****************************************************************************/
extern Set *bigintset_in(const char *str);
extern char *bigintset_out(const Set *set);
extern Span *bigintspan_in(const char *str);
extern char *bigintspan_out(const Span *s);
extern SpanSet *bigintspanset_in(const char *str);
extern char *bigintspanset_out(const SpanSet *ss);
extern Set *dateset_in(const char *str);
extern char *dateset_out(const Set *s);
extern Span *datespan_in(const char *str);
extern char *datespan_out(const Span *s);
extern SpanSet *datespanset_in(const char *str);
extern char *datespanset_out(const SpanSet *ss);
extern Set *floatset_in(const char *str);
extern char *floatset_out(const Set *set, int maxdd);
extern Span *floatspan_in(const char *str);
extern char *floatspan_out(const Span *s, int maxdd);
extern SpanSet *floatspanset_in(const char *str);
extern char *floatspanset_out(const SpanSet *ss, int maxdd);
extern Set *geogset_in(const char *str);
extern Set *geomset_in(const char *str);
extern char *geoset_as_ewkt(const Set *set, int maxdd);
extern char *geoset_as_text(const Set *set, int maxdd);
extern char *geoset_out(const Set *set, int maxdd);
extern Set *intset_in(const char *str);
extern char *intset_out(const Set *set);
extern Span *intspan_in(const char *str);
extern char *intspan_out(const Span *s);
extern SpanSet *intspanset_in(const char *str);
extern char *intspanset_out(const SpanSet *ss);
extern char *set_as_hexwkb(const Set *s, uint8_t variant, size_t *size_out);
extern uint8_t *set_as_wkb(const Set *s, uint8_t variant, size_t *size_out);
extern Set *set_from_hexwkb(const char *hexwkb);
extern Set *set_from_wkb(const uint8_t *wkb, size_t size);
extern char *span_as_hexwkb(const Span *s, uint8_t variant, size_t *size_out);
extern uint8_t *span_as_wkb(const Span *s, uint8_t variant, size_t *size_out);
extern Span *span_from_hexwkb(const char *hexwkb);
extern Span *span_from_wkb(const uint8_t *wkb, size_t size);
extern char *spanset_as_hexwkb(const SpanSet *ss, uint8_t variant, size_t *size_out);
extern uint8_t *spanset_as_wkb(const SpanSet *ss, uint8_t variant, size_t *size_out);
extern SpanSet *spanset_from_hexwkb(const char *hexwkb);
extern SpanSet *spanset_from_wkb(const uint8_t *wkb, size_t size);
extern Set *textset_in(const char *str);
extern char *textset_out(const Set *set);
extern Set *tstzset_in(const char *str);
extern char *tstzset_out(const Set *set);
extern Span *tstzspan_in(const char *str);
extern char *tstzspan_out(const Span *s);
extern SpanSet *tstzspanset_in(const char *str);
extern char *tstzspanset_out(const SpanSet *ss);
/*****************************************************************************
* Constructor functions for set and span types
*****************************************************************************/
extern Set *bigintset_make(const int64 *values, int count);
extern Span *bigintspan_make(int64 lower, int64 upper, bool lower_inc, bool upper_inc);
extern Set *dateset_make(const DateADT *values, int count);
extern Span *datespan_make(DateADT lower, DateADT upper, bool lower_inc, bool upper_inc);
extern Set *floatset_make(const double *values, int count);
extern Span *floatspan_make(double lower, double upper, bool lower_inc, bool upper_inc);
extern Set *geoset_make(const GSERIALIZED **values, int count);
extern Set *intset_make(const int *values, int count);
extern Span *intspan_make(int lower, int upper, bool lower_inc, bool upper_inc);
extern Set *set_copy(const Set *s);
extern Span *span_copy(const Span *s);
extern SpanSet *spanset_copy(const SpanSet *ss);
extern SpanSet *spanset_make(Span *spans, int count, bool normalize, bool order);
extern Set *textset_make(const text **values, int count);
extern Set *tstzset_make(const TimestampTz *values, int count);
extern Span *tstzspan_make(TimestampTz lower, TimestampTz upper, bool lower_inc, bool upper_inc);
/*****************************************************************************
* Conversion functions for set and span types
*****************************************************************************/
extern Set *bigint_to_set(int64 i);
extern Span *bigint_to_span(int i);
extern SpanSet *bigint_to_spanset(int i);
extern Set *date_to_set(DateADT d);
extern Span *date_to_span(DateADT d);
extern SpanSet *date_to_spanset(DateADT d);
extern Set *dateset_to_tstzset(const Set *s);
extern Span *datespan_to_tstzspan(const Span *s);
extern SpanSet *datespanset_to_tstzspanset(const SpanSet *ss);
extern Set *float_to_set(double d);
extern Span *float_to_span(double d);
extern SpanSet *float_to_spanset(double d);
extern Set *floatset_to_intset(const Set *s);
extern Span *floatspan_to_intspan(const Span *s);
extern SpanSet *floatspanset_to_intspanset(const SpanSet *ss);
extern Set *geo_to_set(GSERIALIZED *gs);
extern Set *int_to_set(int i);
extern Span *int_to_span(int i);
extern SpanSet *int_to_spanset(int i);
extern Set *intset_to_floatset(const Set *s);
extern Span *intspan_to_floatspan(const Span *s);
extern SpanSet *intspanset_to_floatspanset(const SpanSet *ss);
extern SpanSet *set_to_spanset(const Set *s);
extern SpanSet *span_to_spanset(const Span *s);
extern Set *text_to_set(text *txt);
extern Set *timestamptz_to_set(TimestampTz t);
extern Span *timestamptz_to_span(TimestampTz t);
extern SpanSet *timestamptz_to_spanset(TimestampTz t);
extern Set *tstzset_to_dateset(const Set *s);
extern Span *tstzspan_to_datespan(const Span *s);
extern SpanSet *tstzspanset_to_datespanset(const SpanSet *ss);
/*****************************************************************************
* Accessor functions for set and span types
*****************************************************************************/
extern int64 bigintset_end_value(const Set *s);
extern int64 bigintset_start_value(const Set *s);
extern bool bigintset_value_n(const Set *s, int n, int64 *result);
extern int64 *bigintset_values(const Set *s);
extern int64 bigintspan_lower(const Span *s);
extern int64 bigintspan_upper(const Span *s);
extern int64 bigintspan_width(const Span *s);
extern int64 bigintspanset_lower(const SpanSet *ss);
extern int64 bigintspanset_upper(const SpanSet *ss);