MobilityDB 1.1
tpoint_spatialfuncs.h
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 * This MobilityDB code is provided under The PostgreSQL License.
4 * Copyright (c) 2016-2023, Université libre de Bruxelles and MobilityDB
5 * contributors
6 *
7 * MobilityDB includes portions of PostGIS version 3 source code released
8 * under the GNU General Public License (GPLv2 or later).
9 * Copyright (c) 2001-2023, PostGIS contributors
10 *
11 * Permission to use, copy, modify, and distribute this software and its
12 * documentation for any purpose, without fee, and without a written
13 * agreement is hereby granted, provided that the above copyright notice and
14 * this paragraph and the following two paragraphs appear in all copies.
15 *
16 * IN NO EVENT SHALL UNIVERSITE LIBRE DE BRUXELLES BE LIABLE TO ANY PARTY FOR
17 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
18 * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
19 * EVEN IF UNIVERSITE LIBRE DE BRUXELLES HAS BEEN ADVISED OF THE POSSIBILITY
20 * OF SUCH DAMAGE.
21 *
22 * UNIVERSITE LIBRE DE BRUXELLES SPECIFICALLY DISCLAIMS ANY WARRANTIES,
23 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON
25 * AN "AS IS" BASIS, AND UNIVERSITE LIBRE DE BRUXELLES HAS NO OBLIGATIONS TO
26 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 
27 *
28 *****************************************************************************/
29
34#ifndef __TPOINT_SPATIALFUNCS_H__
35#define __TPOINT_SPATIALFUNCS_H__
36
37/* PostgreSQL */
38#include <postgres.h>
39/* PostGIS */
40#include <liblwgeom.h>
41/* MEOS */
42#include "general/temporal.h"
43#include "point/tpoint.h"
44
46#define GEOM_TO_GEOG true
47#define GEOG_TO_GEOM false
48
49/*****************************************************************************/
50
51/* Utility functions */
52
53extern POINT2D datum_point2d(Datum value);
54extern POINT3DZ datum_point3dz(Datum value);
55extern void datum_point4d(Datum value, POINT4D *p);
56
57extern const POINT2D *datum_point2d_p(Datum value);
58extern const POINT2D *gserialized_point2d_p(const GSERIALIZED *gs);
59extern const POINT3DZ *datum_point3dz_p(Datum value);
60extern const POINT3DZ *gserialized_point3dz_p(const GSERIALIZED *gs);
61
62extern bool datum_point_eq(Datum geopoint1, Datum geopoint2);
63extern Datum datum2_point_eq(Datum geopoint1, Datum geopoint2);
64extern Datum datum2_point_ne(Datum geopoint1, Datum geopoint2);
65
66extern GSERIALIZED *geo_serialize(const LWGEOM *geom);
67extern Datum datum_transform(Datum value, Datum srid);
68
69/* Generic functions */
70
71extern datum_func2 distance_fn(int16 flags);
72extern datum_func2 pt_distance_fn(int16 flags);
73extern Datum geom_distance2d(Datum geom1, Datum geom2);
74extern Datum geom_distance3d(Datum geom1, Datum geom2);
75extern Datum geog_distance(Datum geog1, Datum geog2);
76extern Datum pt_distance2d(Datum geom1, Datum geom2);
77extern Datum pt_distance3d(Datum geom1, Datum geom2);
78extern Datum geom_intersection2d(Datum geom1, Datum geom2);
79
80/* Parameter tests */
81
82extern void ensure_spatial_validity(const Temporal *temp1,
83 const Temporal *temp2);
84extern void ensure_not_geodetic(int16 flags);
85extern void ensure_same_geodetic(int16 flags1, int16 flags2);
86extern void ensure_same_srid(int32_t srid1, int32_t srid2);
87extern void ensure_same_srid_stbox(const STBox *box1, const STBox *box2);
88extern void ensure_same_srid_tpoint_stbox(const Temporal *temp,
89 const STBox *box);
90extern void ensure_same_srid_stbox_gs(const STBox *box, const GSERIALIZED *gs);
91extern void ensure_same_dimensionality(int16 flags1, int16 flags2);
92extern void ensure_same_spatial_dimensionality(int16 flags1, int16 flags2);
94extern void ensure_same_dimensionality_gs(const GSERIALIZED *gs1,
95 const GSERIALIZED *gs2);
97 const GSERIALIZED *gs);
99 const GSERIALIZED *gs);
100extern void ensure_has_Z(int16 flags);
101extern void ensure_has_not_Z(int16 flags);
102extern void ensure_has_Z_gs(const GSERIALIZED *gs);
103extern void ensure_has_not_Z_gs(const GSERIALIZED *gs);
104extern void ensure_has_M_gs(const GSERIALIZED *gs);
105extern void ensure_has_not_M_gs(const GSERIALIZED *gs);
106extern void ensure_point_type(const GSERIALIZED *gs);
107extern void ensure_non_empty(const GSERIALIZED *gs);
108
109/* Functions derived from PostGIS to increase floating-point precision */
110
111extern long double closest_point2d_on_segment_ratio(const POINT2D *p,
112 const POINT2D *A, const POINT2D *B, POINT2D *closest);
113extern long double closest_point3dz_on_segment_ratio(const POINT3DZ *p,
114 const POINT3DZ *A, const POINT3DZ *B, POINT3DZ *closest);
115extern long double closest_point_on_segment_sphere(const POINT4D *p,
116 const POINT4D *A, const POINT4D *B, POINT4D *closest, double *dist);
117extern void interpolate_point4d_sphere(const POINT3D *p1, const POINT3D *p2,
118 const POINT4D *v1, const POINT4D *v2, double f, POINT4D *p);
119
120/* Functions specializing the PostGIS functions ST_LineInterpolatePoint and
121 * ST_LineLocatePoint */
122
123extern GSERIALIZED *gspoint_make(double x, double y, double z, bool hasz,
124 bool geodetic, int32 srid);
126 long double ratio);
127extern long double geosegm_locate_point(Datum start, Datum end, Datum point,
128 double *dist);
129
130/* Intersection functions */
131
132extern bool tpointsegm_intersection_value(const TInstant *inst1,
133 const TInstant *inst2, Datum value, TimestampTz *t);
134extern bool tgeompointsegm_intersection(const TInstant *start1,
135 const TInstant *end1, const TInstant *start2, const TInstant *end2,
136 TimestampTz *t);
137extern bool tgeogpointsegm_intersection(const TInstant *start1,
138 const TInstant *end1, const TInstant *start2, const TInstant *end2,
139 TimestampTz *t);
140
141extern bool geopoint_collinear(Datum value1, Datum value2, Datum value3,
142 double ratio, bool hasz, bool geodetic);
143
144/* Trajectory functions */
145
146extern LWGEOM **lwpointarr_remove_duplicates(LWGEOM **points, int count,
147 int *newcount);
148extern LWGEOM *lwpointarr_make_trajectory(LWGEOM **lwpoints, int count,
149 interpType interp);
150extern LWLINE *lwline_make(Datum value1, Datum value2);
151
152/* Functions for spatial reference systems */
153
154extern TInstant *tpointinst_transform(const TInstant *inst, int srid);
155extern TSequence *tpointdiscseq_transform(const TSequence *is, int srid);
156extern TSequence *tpointcontseq_transform(const TSequence *seq, int srid);
157extern TSequenceSet *tpointseqset_transform(const TSequenceSet *ss, int srid);
158extern Temporal *tpoint_transform(const Temporal *temp, int srid);
159
160/* Set precision of the coordinates */
161
162extern Datum datum_round_geo(Datum value, Datum prec);
163extern Temporal *tpoint_round(const Temporal *temp, int prec);
164
165/* Functions for extracting coordinates */
166
167extern Temporal *tpoint_get_coord(const Temporal *temp, int coord);
168
169/* Restriction functions */
170
171extern TSequence **tpointseq_at_geometry(const TSequence *seq,
172 const GSERIALIZED *gs, int *count);
173extern Temporal *tpoint_at_stbox1(const Temporal *temp, const STBox *box,
174 bool upper_inc);
175extern Temporal *tpoint_minus_stbox(const Temporal *temp, const STBox *box);
176extern Span **tpointseq_interperiods(const TSequence *seq,
177 GSERIALIZED *gsinter, int *count);
178
179/*****************************************************************************/
180
181#endif
Temporal * tpoint_minus_stbox(const Temporal *temp, const STBox *box)
Restrict a temporal point to the complement of a spatiotemporal box.
Definition: tpoint_spatialfuncs.c:4492
Temporal * tpoint_get_coord(const Temporal *temp, int coord)
Get one of the coordinates of a temporal point as a temporal float.
Definition: tpoint_spatialfuncs.c:2115
Temporal * tpoint_round(const Temporal *temp, int prec)
Set the precision of the coordinates of a temporal point to a number of decimal places.
Definition: tpoint_spatialfuncs.c:740
signed short int16
Functions for building a cache of temporal types and operators.
Definition: meos_catalog.h:41
Datum(* datum_func2)(Datum, Datum)
Definition: temporal.h:367
const POINT2D * datum_point2d_p(Datum value)
Return a pointer to a 2D point from the datum.
Definition: tpoint_spatialfuncs.c:137
Datum geom_distance2d(Datum geom1, Datum geom2)
Return the 2D distance between the two geometries.
Definition: tpoint_spatialfuncs.c:273
void ensure_has_not_Z(int16 flags)
Ensure that a temporal point has not Z dimension.
Definition: tpoint_spatialfuncs.c:517
long double closest_point_on_segment_sphere(const POINT4D *p, const POINT4D *A, const POINT4D *B, POINT4D *closest, double *dist)
Return a float between 0 and 1 representing the location of the closest point on the geography segmen...
Definition: tpoint_spatialfuncs.c:1060
void ensure_same_srid_tpoint_stbox(const Temporal *temp, const STBox *box)
Ensure that a temporal point and a spatiotemporal boxes have the same SRID.
Definition: tpoint_spatialfuncs.c:402
void ensure_same_srid(int32_t srid1, int32_t srid2)
Ensure that the two spatial "objects" have the same SRID.
Definition: tpoint_spatialfuncs.c:378
void interpolate_point4d_sphere(const POINT3D *p1, const POINT3D *p2, const POINT4D *v1, const POINT4D *v2, double f, POINT4D *p)
Find interpolation point p between geography points p1 and p2 so that the len(p1,p) == len(p1,...
Definition: tpoint_spatialfuncs.c:1108
void ensure_has_Z_gs(const GSERIALIZED *gs)
Ensure that the geometry/geography has not Z dimension.
Definition: tpoint_spatialfuncs.c:528
Temporal * tpoint_transform(const Temporal *temp, int srid)
Transform a temporal point into another spatial reference system.
Definition: tpoint_spatialfuncs.c:322
Datum geom_intersection2d(Datum geom1, Datum geom2)
Return the 2D intersection between the two geometries.
Definition: tpoint_spatialfuncs.c:325
TSequence ** tpointseq_at_geometry(const TSequence *seq, const GSERIALIZED *gs, int *count)
Restrict a temporal point to (the complement of) a geometry.
Definition: tpoint_spatialfuncs.c:4015
Span ** tpointseq_interperiods(const TSequence *seq, GSERIALIZED *gsinter, int *count)
Get the periods at which a temporal sequence point with linear interpolation intersects a geometry.
Definition: tpoint_spatialfuncs.c:3799
long double geosegm_locate_point(Datum start, Datum end, Datum point, double *dist)
Return a float between 0 and 1 representing the location of the closest point on the geometry segment...
Definition: tpoint_spatialfuncs.c:1201
bool tgeogpointsegm_intersection(const TInstant *start1, const TInstant *end1, const TInstant *start2, const TInstant *end2, TimestampTz *t)
Return true if two segments of twp temporal geographic points intersect at a timestamp.
Definition: tpoint_spatialfuncs.c:1419
TInstant * tpointinst_transform(const TInstant *inst, int srid)
Transform a temporal point into another spatial reference system.
Definition: tpoint_spatialfuncs.c:197
Datum datum_round_geo(Datum value, Datum prec)
Set the precision of the coordinates to the number of decimal places.
Definition: tpoint_spatialfuncs.c:688
void ensure_same_geodetic(int16 flags1, int16 flags2)
Ensure that the spatiotemporal argument have the same type of coordinates, either planar or geodetic.
Definition: tpoint_spatialfuncs.c:366
datum_func2 pt_distance_fn(int16 flags)
Select the appropriate distance function.
Definition: tpoint_spatialfuncs.c:257
void ensure_has_Z(int16 flags)
Ensure that a temporal point has Z dimension.
Definition: tpoint_spatialfuncs.c:506
Temporal * tpoint_at_stbox1(const Temporal *temp, const STBox *box, bool upper_inc)
Restrict a temporal point to a spatiotemporal box.
Definition: tpoint_spatialfuncs.c:4336
void ensure_same_spatial_dimensionality_temp_box(int16 flags1, int16 flags2)
Ensure that a temporal point and a spatiotemporal box have the same spatial dimensionality as given b...
Definition: tpoint_spatialfuncs.c:454
void ensure_same_spatial_dimensionality_stbox_gs(const STBox *box1, const GSERIALIZED *gs)
Ensure that the spatiotemporal boxes have the same spatial dimensionality.
Definition: tpoint_spatialfuncs.c:492
TSequence * tpointdiscseq_transform(const TSequence *is, int srid)
void ensure_same_spatial_dimensionality(int16 flags1, int16 flags2)
Ensure that two temporal points have the same spatial dimensionality as given by their flags.
Definition: tpoint_spatialfuncs.c:441
Datum datum2_point_ne(Datum geopoint1, Datum geopoint2)
Return true if the points are equal.
Definition: tpoint_spatialfuncs.c:214
void ensure_same_srid_stbox_gs(const STBox *box, const GSERIALIZED *gs)
Ensure that a temporal point and a geometry/geography have the same SRID.
Definition: tpoint_spatialfuncs.c:415
Datum datum_transform(Datum value, Datum srid)
Call the PostGIS transform function.
Definition: tpoint_spatialfuncs.c:187
void ensure_same_dimensionality_tpoint_gs(const Temporal *temp, const GSERIALIZED *gs)
Ensure that a temporal point and a geometry/geography have the same dimensionality.
Definition: tpoint_spatialfuncs.c:480
long double closest_point2d_on_segment_ratio(const POINT2D *p, const POINT2D *A, const POINT2D *B, POINT2D *closest)
Return a long double between 0 and 1 representing the location of the closest point on the segment to...
Definition: tpoint_spatialfuncs.c:967
Datum pt_distance2d(Datum geom1, Datum geom2)
Return the 2D distance between the two geometric points.
Definition: tpoint_spatialfuncs.c:303
void ensure_point_type(const GSERIALIZED *gs)
Ensure that the geometry/geography is a point.
Definition: tpoint_spatialfuncs.c:572
bool datum_point_eq(Datum geopoint1, Datum geopoint2)
Return true if the points are equal.
Definition: tpoint_spatialfuncs.c:175
POINT3DZ datum_point3dz(Datum value)
Return a 3DZ point from the datum.
Definition: tpoint_spatialfuncs.c:99
void ensure_has_M_gs(const GSERIALIZED *gs)
Ensure that the geometry/geography has M dimension.
Definition: tpoint_spatialfuncs.c:550
TSequence * tpointcontseq_transform(const TSequence *seq, int srid)
LWGEOM ** lwpointarr_remove_duplicates(LWGEOM **points, int count, int *newcount)
Remove duplicates from an array of LWGEOM points.
Definition: tpoint_spatialfuncs.c:1561
void ensure_not_geodetic(int16 flags)
Ensure that the spatiotemporal argument has planar coordinates.
Definition: tpoint_spatialfuncs.c:354
void datum_point4d(Datum value, POINT4D *p)
Return a 4D point from the datum.
Definition: tpoint_spatialfuncs.c:111
void ensure_same_dimensionality_gs(const GSERIALIZED *gs1, const GSERIALIZED *gs2)
Ensure that two geometries/geographies have the same dimensionality.
Definition: tpoint_spatialfuncs.c:468
const POINT2D * gserialized_point2d_p(const GSERIALIZED *gs)
Return a 2D point from the serialized geometry.
Definition: tpoint_spatialfuncs.c:147
Datum geom_distance3d(Datum geom1, Datum geom2)
Return the 3D distance between the two geometries.
Definition: tpoint_spatialfuncs.c:283
GSERIALIZED * geo_serialize(const LWGEOM *geom)
Serialize a geometry/geography.
Definition: tpoint_spatialfuncs.c:226
GSERIALIZED * gspoint_make(double x, double y, double z, bool hasz, bool geodetic, int32 srid)
Create a point.
Definition: tpoint_spatialfuncs.c:1136
const POINT3DZ * datum_point3dz_p(Datum value)
Return a pointer to a 3DZ point from the datum.
Definition: tpoint_spatialfuncs.c:156
void ensure_has_not_Z_gs(const GSERIALIZED *gs)
Ensure that the geometry/geography has not Z dimension.
Definition: tpoint_spatialfuncs.c:539
bool tpointsegm_intersection_value(const TInstant *inst1, const TInstant *inst2, Datum value, TimestampTz *t)
Return true if a segment of a temporal point value intersects a point at the timestamp.
Definition: tpoint_spatialfuncs.c:1278
Datum geosegm_interpolate_point(Datum start, Datum end, long double ratio)
Return a point interpolated from the geometry/geography segment with respect to the fraction of its t...
Definition: tpoint_spatialfuncs.c:1156
void ensure_same_srid_stbox(const STBox *box1, const STBox *box2)
Ensure that the spatiotemporal boxes have the same SRID.
Definition: tpoint_spatialfuncs.c:389
bool tgeompointsegm_intersection(const TInstant *start1, const TInstant *end1, const TInstant *start2, const TInstant *end2, TimestampTz *t)
Return true if two segments of a temporal geometric points intersect at a timestamp.
Definition: tpoint_spatialfuncs.c:1311
LWLINE * lwline_make(Datum value1, Datum value2)
Compute the trajectory from two geometry points.
Definition: tpoint_spatialfuncs.c:1609
void ensure_has_not_M_gs(const GSERIALIZED *gs)
Ensure that the geometry/geography has not M dimension.
Definition: tpoint_spatialfuncs.c:561
Datum datum2_point_eq(Datum geopoint1, Datum geopoint2)
Return true if the points are equal.
Definition: tpoint_spatialfuncs.c:205
void ensure_spatial_validity(const Temporal *temp1, const Temporal *temp2)
Ensure that the spatial constraints required for operating on two temporal geometries are satisfied.
Definition: tpoint_spatialfuncs.c:340
Datum geog_distance(Datum geog1, Datum geog2)
Return the distance between the two geographies.
Definition: tpoint_spatialfuncs.c:293
void ensure_same_dimensionality(int16 flags1, int16 flags2)
Ensure that two temporal points have the same dimensionality as given by their flags.
Definition: tpoint_spatialfuncs.c:427
bool geopoint_collinear(Datum value1, Datum value2, Datum value3, double ratio, bool hasz, bool geodetic)
Return true if the three values are collinear.
Definition: tpoint_spatialfuncs.c:1472
POINT2D datum_point2d(Datum value)
Return a 2D point from the datum.
Definition: tpoint_spatialfuncs.c:88
LWGEOM * lwpointarr_make_trajectory(LWGEOM **lwpoints, int count, interpType interp)
Compute a trajectory from a set of points.
Definition: tpoint_spatialfuncs.c:1589
long double closest_point3dz_on_segment_ratio(const POINT3DZ *p, const POINT3DZ *A, const POINT3DZ *B, POINT3DZ *closest)
Return a float between 0 and 1 representing the location of the closest point on the segment to the g...
Definition: tpoint_spatialfuncs.c:1016
void ensure_non_empty(const GSERIALIZED *gs)
Ensure that the geometry/geography is not empty.
Definition: tpoint_spatialfuncs.c:583
TSequenceSet * tpointseqset_transform(const TSequenceSet *ss, int srid)
Transform a temporal point into another spatial reference system.
Definition: tpoint_spatialfuncs.c:253
Datum pt_distance3d(Datum geom1, Datum geom2)
Return the 3D distance between the two geometric points.
Definition: tpoint_spatialfuncs.c:314
const POINT3DZ * gserialized_point3dz_p(const GSERIALIZED *gs)
Return a 3DZ point from the serialized geometry.
Definition: tpoint_spatialfuncs.c:166
datum_func2 distance_fn(int16 flags)
Select the appropriate distance function.
Definition: tpoint_spatialfuncs.c:242
interpType
Enumeration that defines the interpolation types used in MobilityDB.
Definition: meos.h:124
int64 TimestampTz
Definition: pg_ext_defs.in.h:19
uintptr_t Datum
Definition: pg_ext_defs.in.h:4
signed int int32
Definition: pg_ext_defs.in.h:8
Definition: postgis_ext_defs.in.h:139
Definition: postgis_ext_defs.in.h:153
Definition: postgis_ext_defs.in.h:177
Definition: postgis_ext_defs.in.h:85
Definition: postgis_ext_defs.in.h:91
Definition: postgis_ext_defs.in.h:97
Definition: postgis_ext_defs.in.h:109
Structure to represent spatiotemporal boxes.
Definition: meos.h:107
Structure to represent spans (a.k.a.
Definition: meos.h:70
Structure to represent temporal values of instant subtype.
Definition: meos.h:148
Structure to represent temporal values of sequence set subtype.
Definition: meos.h:186
Structure to represent temporal values of instant set or sequence subtype.
Definition: meos.h:165
Structure to represent the common structure of temporal values of any temporal subtype.
Definition: meos.h:136