MobilityDB  1.0
tpoint.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * This MobilityDB code is provided under The PostgreSQL License.
4  *
5  * Copyright (c) 2016-2021, Université libre de Bruxelles and MobilityDB
6  * contributors
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose, without fee, and without a written
10  * agreement is hereby granted, provided that the above copyright notice and
11  * this paragraph and the following two paragraphs appear in all copies.
12  *
13  * IN NO EVENT SHALL UNIVERSITE LIBRE DE BRUXELLES BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
15  * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
16  * EVEN IF UNIVERSITE LIBRE DE BRUXELLES HAS BEEN ADVISED OF THE POSSIBILITY
17  * OF SUCH DAMAGE.
18  *
19  * UNIVERSITE LIBRE DE BRUXELLES SPECIFICALLY DISCLAIMS ANY WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON
22  * AN "AS IS" BASIS, AND UNIVERSITE LIBRE DE BRUXELLES HAS NO OBLIGATIONS TO
23  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 
24  *
25  *****************************************************************************/
26 
32 #ifndef __TPOINT_H__
33 #define __TPOINT_H__
34 
35 #include <postgres.h>
36 #include <catalog/pg_type.h>
37 
38 #include "general/temporal.h"
39 
40 #include <liblwgeom.h>
41 #include "stbox.h"
42 
43 /*****************************************************************************
44  * Macros for manipulating the 'typmod' int. An int32_t used as follows:
45  * Plus/minus = Top bit.
46  * Spare bits = Next 2 bits.
47  * SRID = Next 21 bits.
48  * TYPE = Next 6 bits.
49  * ZM Flags = Bottom 2 bits.
50  *****************************************************************************/
51 
52 /* The following (commented out) definitions are taken from POSTGIS
53 #define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x0FFFFF00) - ((typmod) & 0x10000000)) >> 8)
54 #define TYPMOD_SET_SRID(typmod, srid) ((typmod) = (((typmod) & 0xE00000FF) | ((srid & 0x001FFFFF)<<8)))
55 #define TYPMOD_GET_TYPE(typmod) ((typmod & 0x000000FC)>>2)
56 #define TYPMOD_SET_TYPE(typmod, type) ((typmod) = (typmod & 0xFFFFFF03) | ((type & 0x0000003F)<<2))
57 #define TYPMOD_GET_Z(typmod) ((typmod & 0x00000002)>>1)
58 #define TYPMOD_SET_Z(typmod) ((typmod) = typmod | 0x00000002)
59 #define TYPMOD_GET_M(typmod) (typmod & 0x00000001)
60 #define TYPMOD_SET_M(typmod) ((typmod) = typmod | 0x00000001)
61 #define TYPMOD_GET_NDIMS(typmod) (2+TYPMOD_GET_Z(typmod)+TYPMOD_GET_M(typmod))
62 */
63 
64 /* In order to reuse the above (commented out) macros for manipulating the
65  typmod from POSTGIS we need to shift them to take into account that the
66  first 4 bits are taken for the temporal type */
67 
68 #define TYPMOD_DEL_SUBTYPE(typmod) (typmod = typmod >> 4 )
69 #define TYPMOD_SET_SUBTYPE(typmod, subtype) ((typmod) = typmod << 4 | subtype)
70 
71 /*****************************************************************************
72  * Well-Known Binary (WKB)
73  *****************************************************************************/
74 
75 /* Data type size */
76 #define WKB_TIMESTAMP_SIZE 8 /* Internal use only */
77 #define WKB_DOUBLE_SIZE 8 /* Internal use only */
78 #define WKB_INT_SIZE 4 /* Internal use only */
79 #define WKB_BYTE_SIZE 1 /* Internal use only */
80 
81 /* Subtype */
82 #define MOBDB_WKB_INSTANT 1
83 #define MOBDB_WKB_INSTANTSET 2
84 #define MOBDB_WKB_SEQUENCE 3
85 #define MOBDB_WKB_SEQUENCESET 4
86 
87 /* Period bounds */
88 #define MOBDB_WKB_LOWER_INC 0x01
89 #define MOBDB_WKB_UPPER_INC 0x02
90 
91 /* Machine endianness */
92 #define XDR 0 /* big endian */
93 #define NDR 1 /* little endian */
94 
95 /* Variation flags */
96 #define MOBDB_WKB_ZFLAG 0x10
97 #define MOBDB_WKB_GEODETICFLAG 0x20
98 #define MOBDB_WKB_SRIDFLAG 0x40
99 #define MOBDB_WKB_LINEAR_INTERP 0x80
100 
101 /*****************************************************************************
102  * Miscellaneous functions defined in TemporalPoint.c
103  *****************************************************************************/
104 
105 extern void temporalgeom_init();
106 #if POSTGIS_VERSION_NUMBER >= 30000
107 extern GSERIALIZED * gserialized_copy(const GSERIALIZED *g);
108 #endif
109 
110 /* Input/output functions */
111 
112 extern Datum tpoint_in(PG_FUNCTION_ARGS);
113 extern Datum tgeompoint_typmod_in(PG_FUNCTION_ARGS);
114 extern Datum tgeogpoint_typmod_in(PG_FUNCTION_ARGS);
115 extern Datum tpoint_typmod_out(PG_FUNCTION_ARGS);
116 extern Datum tpoint_enforce_typmod(PG_FUNCTION_ARGS);
117 
118 /* Constructor functions */
119 
120 extern Datum tpointinst_constructor(PG_FUNCTION_ARGS);
121 
122 /* Accessor functions */
123 
124 extern Datum tpoint_stbox(PG_FUNCTION_ARGS);
125 
126 /* Ever/always comparison operators */
127 
128 extern Datum tpoint_values(PG_FUNCTION_ARGS);
129 extern Datum tpoint_stbox(PG_FUNCTION_ARGS);
130 
131 /* Temporal comparisons */
132 
133 extern Datum teq_geo_tpoint(PG_FUNCTION_ARGS);
134 extern Datum teq_tpoint_geo(PG_FUNCTION_ARGS);
135 extern Datum tne_geo_tpoint(PG_FUNCTION_ARGS);
136 extern Datum tne_tpoint_geo(PG_FUNCTION_ARGS);
137 
138 /*****************************************************************************/
139 
140 #endif
Datum tpoint_enforce_typmod(PG_FUNCTION_ARGS)
Enforce typmod information for temporal points with respect to temporal type, dimensions, and SRID.
Definition: tpoint.c:387
Datum tpoint_typmod_out(PG_FUNCTION_ARGS)
Output typmod information for temporal points.
Definition: tpoint.c:343
GSERIALIZED * gserialized_copy(const GSERIALIZED *g)
Copy a GSERIALIZED.
Definition: tpoint.c:95
Basic functions for temporal types of any subtype.
Datum tpoint_values(PG_FUNCTION_ARGS)
Returns the base values (that is, the trajectory) of the temporal point value as a geometry/geography...
Definition: tpoint.c:534
Datum tpoint_stbox(PG_FUNCTION_ARGS)
Datum tne_geo_tpoint(PG_FUNCTION_ARGS)
Returns the temporal difference of the base value and the temporal value.
Definition: tpoint.c:508
Datum teq_tpoint_geo(PG_FUNCTION_ARGS)
Returns the temporal equality of the temporal value and base value.
Definition: tpoint.c:498
Datum tgeompoint_typmod_in(PG_FUNCTION_ARGS)
Input typmod information for temporal geometric points.
Definition: tpoint.c:316
void temporalgeom_init()
Set the handlers for initializing the liblwgeom library.
Definition: tpoint.c:86
Datum teq_geo_tpoint(PG_FUNCTION_ARGS)
Returns the temporal equality of the base value and the temporal value.
Definition: tpoint.c:488
Datum tne_tpoint_geo(PG_FUNCTION_ARGS)
Returns the temporal difference of the temporal value and base value.
Definition: tpoint.c:518
Functions for spatiotemporal bounding boxes.
Datum tpoint_in(PG_FUNCTION_ARGS)
Generic input function for temporal points.
Definition: tpoint.c:174
Datum tgeogpoint_typmod_in(PG_FUNCTION_ARGS)
Input typmod information for temporal geographic points.
Definition: tpoint.c:328
Datum tpointinst_constructor(PG_FUNCTION_ARGS)
Construct a temporal instant point value from the arguments.
Definition: tpoint.c:405