MobilityDB 1.3
Loading...
Searching...
No Matches
Macros | Enumerations | Functions | Variables
tpoint_spatialfuncs.c File Reference

Spatial functions for temporal points. More...

#include "geo/tgeo_spatialfuncs.h"
#include <assert.h>
#include <utils/float.h>
#include <liblwgeom.h>
#include <liblwgeom_internal.h>
#include <lwgeodetic.h>
#include <lwgeom_geos.h>
#include <meos.h>
#include <meos_internal.h>
#include <meos_internal_geo.h>
#include "temporal/postgres_types.h"
#include "temporal/lifting.h"
#include "temporal/temporal_compops.h"
#include "temporal/tnumber_mathfuncs.h"
#include "temporal/tsequence.h"
#include "temporal/type_util.h"
#include "geo/postgis_funcs.h"
#include "geo/stbox.h"
#include "geo/tgeo.h"
#include "geo/tgeo_distance.h"

Macros

#define DELTA_UNIX_POSTGRES_EPOCH   946684800
 
#define PGIS_FP_TOLERANCE   1e-12
 

Enumerations

enum  {
  MEOS_SEG_NO_INTERSECTION , MEOS_SEG_OVERLAP , MEOS_SEG_CROSS , MEOS_SEG_TOUCH_END ,
  MEOS_SEG_TOUCH
}
 

Functions

static double alpha (const POINT2D *p1, const POINT2D *p2)
 Normalize the bearing from -180° to + 180° (in radians) to 0° to 360° (in radians) More...
 
bool bearing_point_point (const GSERIALIZED *gs1, const GSERIALIZED *gs2, double *result)
 Return the temporal bearing between two geometry/geography points. More...
 
Temporalbearing_tpoint_point (const Temporal *temp, const GSERIALIZED *gs, bool invert)
 Return the temporal bearing between a temporal point and a point. More...
 
Temporalbearing_tpoint_tpoint (const Temporal *temp1, const Temporal *temp2)
 Return the temporal bearing between two temporal points. More...
 
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 2D segment to the given point, as a fraction of total segment length. More...
 
long double closest_point3dz_on_segment_ratio (const POINT3DZ *p, const POINT3DZ *A, const POINT3DZ *B, POINT3DZ *closest)
 Return a long double between 0 and 1 representing the location of the closest point on the 3D segment to the given point, as a fraction of total segment length. More...
 
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 segment to the given point, as a fraction of total segment length. More...
 
static Datum datum_geog_azimuth (Datum geog1, Datum geog2)
 Return the azimuth two geography points. More...
 
static Datum datum_geom_azimuth (Datum geom1, Datum geom2)
 Return the azimuth of two geometry points. More...
 
bool ensure_valid_geo_geo (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Ensure the validity of two temporal points. More...
 
bool ensure_valid_tpoint_geo (const Temporal *temp, const GSERIALIZED *gs)
 Ensure the validity of two temporal points. More...
 
bool ensure_valid_tpoint_tpoint (const Temporal *temp1, const Temporal *temp2)
 Ensure the validity of two temporal points. More...
 
static bool ensure_valid_trajectory (const LWGEOM *geom, bool hasz, bool discrete)
 Ensure that a PostGIS trajectory has increasing timestamps. More...
 
static void gbox_init_point2d (const POINT2D *p, GBOX *gbox)
 
static void gbox_merge_point2d (const POINT2D *p, GBOX *gbox)
 
static datum_func2 geo_bearing_fn (int16 flags)
 Select the appropriate bearing function. More...
 
static Datum geog_bearing (Datum point1, Datum point2)
 Return the bearing between two geography points. More...
 
static double geog_distance_geos (const GEOSGeometry *pt1, const GEOSGeometry *pt2)
 Calculate the distance between two geography points given as GEOS geometries. More...
 
static Datum geom_bearing (Datum point1, Datum point2)
 Return the bearing between two geometry points. More...
 
Temporalgeomeas_to_tpoint (const GSERIALIZED *gs)
 Return a geometry/geography with M measure encoding timestamps transformed to a temporal point. More...
 
static TInstantgeomeas_tpointinst (const LWGEOM *geom)
 Return the PostGIS trajectory geometry/geography where the M coordinates encode the timestamps in Unix epoch transformed into a temporal point instant. More...
 
static TInstantgeomeas_tpointinst_iter (LWPOINT *lwpoint)
 Return a geometry/geography where the M coordinates encode the timestamps in Unix epoch transformed into a temporal point instant. More...
 
static TSequencegeomeas_tpointseq_disc (const LWGEOM *geom, bool hasz)
 Return the PostGIS trajectory geometry/geography where the M coordinates encode the timestamps transformed into Unix epoch into a temporal point discrete sequence. More...
 
static TSequencegeomeas_tpointseq_linear (const LWGEOM *geom, bool hasz, bool geodetic)
 Return the PostGIS trajectory geometry/geography where the M coordinates encode the timestamps in Unix epoch transformed into a temporal point sequence. More...
 
static TSequenceSetgeomeas_tpointseqset (const LWGEOM *geom, bool hasz, bool geodetic)
 Return the PostGIS trajectory geometry/geography where the M coordinates encode the timestamps in Unix epoch transformed into a temporal point sequence set. More...
 
bool geopoint_collinear (Datum value1, Datum value2, Datum value3, double ratio, bool hasz, bool geodetic)
 Return true if the three values are collinear. More...
 
GSERIALIZEDgeopointarr_make_trajectory (GSERIALIZED **points, int count, interpType interp)
 Return a trajectory from a set of points. More...
 
GSERIALIZEDgeopointlinearr_make_trajectory (GSERIALIZED **points, int npoints, GSERIALIZED **lines, int nlines)
 Return a trajectory from a set of points and lines. More...
 
void interpolate_point4d_spheroid (const POINT4D *p1, const POINT4D *p2, POINT4D *p, const SPHEROID *s, double f)
 Find the interpolation point p between geography points p1 and p2 so that len(p1,p) == len(p1,p2) * f and p falls on the p1,p2 segment. More...
 
static bool lw_seg_interact (const POINT2D *p1, const POINT2D *p2, const POINT2D *q1, const POINT2D *q2)
 Function derived from file lwalgorithm.c since it is declared static. More...
 
LWGEOMlwcoll_from_points_lines (LWGEOM **points, LWGEOM **lines, int npoints, int nlines)
 Return a geometry from an array of points and lines. More...
 
LWLINElwline_make (Datum value1, Datum value2)
 Return the line connecting two geometry points. More...
 
static int lwpoint_cmp (const LWPOINT *p, const LWPOINT *q)
 Return -1, 0, or 1 depending on whether the first LWPOINT is less than, equal to, or greater than the second one. More...
 
static int lwpoint_sort_cmp (const LWPOINT **l, const LWPOINT **r)
 Comparator function for lwpoints. More...
 
LWGEOMlwpointarr_make_trajectory (LWGEOM **points, int count, interpType interp)
 Return a trajectory from a set of points. More...
 
LWGEOM ** lwpointarr_remove_duplicates (LWGEOM **points, int count, int *newcount)
 Remove duplicates from an array of LWGEOM points. More...
 
void lwpointarr_sort (LWPOINT **points, int count)
 Sort function for lwpoints. More...
 
static double mrr_distance_geos (GEOSGeometry *geom, bool geodetic)
 Calculate the length of the diagonal of the minimum rotated rectangle of the input GEOS geometry. More...
 
static GEOSGeometry * multipoint_add_inst_free (GEOSGeometry *geom, const TInstant *inst)
 Add the point stored in the given instant to a GEOS multipoint geometry. More...
 
static GEOSGeometry * multipoint_make (const TSequence *seq, int start, int end)
 Create a GEOS Multipoint geometry from a part (defined by start and end) of a temporal point sequence. More...
 
static int parseg2d_intersection (const POINT2D *a, const POINT2D *b, const POINT2D *c, const POINT2D *d, POINT2D *p)
 Find the unique intersection point p between two closed collinear segments ab and cd. More...
 
static Datum point_get_x (Datum point)
 Get the X coordinates of a temporal point. More...
 
static Datum point_get_y (Datum point)
 Get the Y coordinates of a temporal point. More...
 
static Datum point_get_z (Datum point)
 Get the Z coordinates of a temporal point. More...
 
static void point_grid (Datum value, bool hasz, const gridspec *grid, POINT4D *p)
 Return in the last argument a temporal point snapped to a grid specification. More...
 
static LWGEOMpoint_meas_to_lwpoint (Datum point, Datum meas)
 Return a geometry/geography point and a measure transformed into a PostGIS point with M coordinates. More...
 
Datum pointsegm_interpolate (Datum start, Datum end, long double ratio)
 Return a point interpolated from the geometry/geography segment with respect to the fraction of its total length. More...
 
long double pointsegm_locate (Datum start, Datum end, Datum point, double *dist)
 Return a float in (0,1) representing the location of the closest point on the line segment to the given point, as a fraction of the total segment length, return -1.0 if the point is not located in the segment or if is approximately equal to the start or to the end point. More...
 
long double pointsegm_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 to the given point, as a fraction of total segment length. More...
 
static int seg2d_intersection (const POINT2D *a, const POINT2D *b, const POINT2D *c, const POINT2D *d, POINT2D *p)
 Find the unique intersection point p between two closed segments ab and cd. More...
 
static int seg2d_side (const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
 Determines the side of segment P where Q lies. More...
 
int tgeogpointsegm_intersection (Datum start1, Datum end1, Datum start2, Datum end2, TimestampTz lower, TimestampTz upper, TimestampTz *t)
 Return 1 if the segments of two temporal geography points intersect at the timestamptz output in the last argument. More...
 
int tgeompointsegm_intersection (Datum start1, Datum end1, Datum start2, Datum end2, TimestampTz lower, TimestampTz upper, TimestampTz *t)
 Return 1 if the segments of two temporal geometry points intersect at the timestamptz output in the last argument. More...
 
Temporaltpoint_angular_difference (const Temporal *temp)
 Return the temporal angular difference of a temporal geometry point. More...
 
bool tpoint_as_mvtgeom (const Temporal *temp, const STBox *bounds, int32_t extent, int32_t buffer, bool clip_geom, GSERIALIZED **gsarr, int64 **timesarr, int *count)
 Return a temporal point transformed to Mapbox Vector Tile format. More...
 
Temporaltpoint_azimuth (const Temporal *temp)
 Return the temporal azimuth of a temporal geometry point. More...
 
Temporaltpoint_cumulative_length (const Temporal *temp)
 Return the cumulative length traversed by a temporal point. More...
 
static GSERIALIZEDtpoint_decouple (const Temporal *temp, int64 **timesarr, int *count)
 Decouple the points and the timestamptz values of a temporal point. More...
 
bool tpoint_direction (const Temporal *temp, double *result)
 Return the direction of a temporal point. More...
 
static int tpoint_geo_bearing_turnpt (Datum start, Datum end, Datum point, TimestampTz lower, TimestampTz upper, TimestampTz *t1, TimestampTz *t2)
 Return the value and timestamptz at which the a temporal point segment and a point are at the minimum bearing. More...
 
Temporaltpoint_get_coord (const Temporal *temp, int coord)
 Return one of the coordinates of a temporal point as a temporal float. More...
 
Temporaltpoint_get_x (const Temporal *temp)
 Return the X coordinates of a temporal point as a temporal float. More...
 
Temporaltpoint_get_y (const Temporal *temp)
 Return the Y coordinates of a temporal point as a temporal float. More...
 
Temporaltpoint_get_z (const Temporal *temp)
 Return the Z coordinates of a temporal point as a temporal float. More...
 
static Temporaltpoint_grid (const Temporal *temp, const gridspec *grid, bool filter_pts)
 Return a temporal point snapped to a grid specification. More...
 
bool tpoint_is_simple (const Temporal *temp)
 Return true if a temporal point does not self-intersect. More...
 
double tpoint_length (const Temporal *temp)
 Return the length traversed by a temporal point sequence (set) More...
 
Temporal ** tpoint_make_simple (const Temporal *temp, int *count)
 Return a temporal point split into an array of non self-intersecting fragments. More...
 
static Temporaltpoint_mvt (const Temporal *tpoint, const STBox *box, uint32_t extent, uint32_t buffer, bool clip_geom)
 Return a temporal point transformed into vector tile coordinate space. More...
 
static Temporaltpoint_remove_repeated_points (const Temporal *temp, double tolerance, int min_points)
 Return a temporal point with consecutive equal points removed. More...
 
Temporaltpoint_speed (const Temporal *temp)
 Return the speed of a temporal point. More...
 
bool tpoint_tfloat_to_geomeas (const Temporal *tpoint, const Temporal *meas, bool segmentize, GSERIALIZED **result)
 Return a geometry/geography with M measure from a temporal point and optionally a temporal float. More...
 
GSERIALIZEDtpoint_trajectory (const Temporal *temp)
 Return the trajectory of a temporal point. More...
 
GSERIALIZEDtpoint_twcentroid (const Temporal *temp)
 Return the time-weighed centroid of a temporal geometry point. More...
 
static GSERIALIZEDtpointinst_decouple (const TInstant *inst, int64 **timesarr, int *count)
 Decouple the points and the timestamptz values of a temporal point instant. More...
 
static TInstanttpointinst_grid (const TInstant *inst, const gridspec *grid)
 Return a temporal point instant snapped to a grid specification. More...
 
static GSERIALIZEDtpointinst_to_geomeas (const TInstant *inst, const TInstant *meas)
 Return a geometry/geography with M measure from a temporal point instant and optionally a temporal float. More...
 
static LWGEOMtpointinst_to_geomeas_iter (const TInstant *inst, const TInstant *meas)
 Return a geometry/geography with M measure from the temporal point instant and optionally a temporal float (iterator function) More...
 
static int tpointsegm_bearing_turnpt (Datum start1, Datum end1, Datum start2, Datum end2, Datum param UNUSED, TimestampTz lower, TimestampTz upper, TimestampTz *t1, TimestampTz *t2)
 Return the value and timestamptz at which two temporal point segments are at the minimum bearing. More...
 
int tpointsegm_intersection_value (Datum start, Datum end, Datum value, TimestampTz lower, TimestampTz upper, TimestampTz *t)
 Return 1 if a segment of a temporal point value intersects a point at the timestamp output in the last argument. More...
 
TSequenceSettpointseq_azimuth (const TSequence *seq)
 Return the temporal azimuth of a temporal geometry point sequence. More...
 
static int tpointseq_azimuth_iter (const TSequence *seq, TSequence **result)
 Return the temporal azimuth of a temporal geometry point sequence (iterator function) More...
 
static TSequence ** tpointseq_cont_split (const TSequence *seq, bool *splits, int count)
 Return a temporal point split into an array of non self-intersecting fragments. More...
 
static GSERIALIZEDtpointseq_cont_to_geomeas (const TSequence *seq, const TSequence *meas)
 Return a geometry/geography with M measure from the temporal point sequence and optionally a temporal float. More...
 
static GSERIALIZEDtpointseq_cont_to_geomeas_segm (const TSequence *seq, const TSequence *meas)
 Return a geometry/geography with M measure from a temporal point sequence and optionally a temporal float. More...
 
TSequencetpointseq_cumulative_length (const TSequence *seq, double prevlength)
 Return the cumulative length traversed by a temporal point sequence. More...
 
static GSERIALIZEDtpointseq_decouple (const TSequence *seq, int64 **timesarr, int *count)
 Decouple the points and the timestamptz values of a temporal point sequence. More...
 
static LWGEOMtpointseq_decouple_iter (const TSequence *seq, int64 *times)
 Decouple the points and the timestamptz values of a temporal point sequence (iterator function) More...
 
bool tpointseq_direction (const TSequence *seq, double *result)
 Return the direction of a temporal point sequence. More...
 
static TSequence ** tpointseq_disc_split (const TSequence *seq, bool *splits, int count)
 Return a temporal point discrete sequence split into an array of non self-intersecting fragments. More...
 
static GSERIALIZEDtpointseq_disc_to_geomeas (const TSequence *seq, const TSequence *meas)
 Return a geometry/geography with M measure from the temporal point discrete sequence and optionally a temporal float. More...
 
static booltpointseq_discstep_find_splits (const TSequence *seq, int *count)
 Return a temporal point sequence with discrete or step interpolation split into an array of non self-intersecting fragments. More...
 
static bool tpointseq_discstep_is_simple (const TSequence *seq)
 Return true if a temporal point does not self-intersect. More...
 
static TSequencetpointseq_grid (const TSequence *seq, const gridspec *grid, bool filter_pts)
 Return a temporal point sequence snapped to a grid specification. More...
 
bool tpointseq_is_simple (const TSequence *seq)
 Return true if a temporal point does not self-intersect. More...
 
double tpointseq_length (const TSequence *seq)
 Return the length traversed by a temporal point sequence. More...
 
static double tpointseq_length_2d (const TSequence *seq)
 Return the length traversed by a temporal geometry point sequence. More...
 
static double tpointseq_length_3d (const TSequence *seq)
 Return the length traversed by a temporal geometry point sequence. More...
 
static booltpointseq_linear_find_splits (const TSequence *seq, int *count)
 Return a temporal point sequence with linear interpolation split into an array of non self-intersecting fragments. More...
 
GSERIALIZEDtpointseq_linear_trajectory (const TSequence *seq, bool unary_union)
 Return the trajectory of a temporal point sequence. More...
 
TSequence ** tpointseq_make_simple (const TSequence *seq, int *count)
 Return a temporal point sequence split into an array of non self-intersecting fragments. More...
 
static TSequencetpointseq_remove_repeated_points (const TSequence *seq, double tolerance, int min_points)
 Return a temporal point with consecutive equal points removed. More...
 
TSequencetpointseq_speed (const TSequence *seq)
 Return the speed of a temporal point sequence. More...
 
int tpointseq_stops_iter (const TSequence *seq, double maxdist, int64 mintunits, TSequence **result)
 Return the subsequences where the temporal value stays within an area with a given maximum size for at least the specified duration (iterator function) More...
 
GSERIALIZEDtpointseq_twcentroid (const TSequence *seq)
 Return the time-weighed centroid of a temporal geometry point sequence. More...
 
void tpointseq_twcentroid_iter (const TSequence *seq, bool hasz, interpType interp, TSequence **seqx, TSequence **seqy, TSequence **seqz)
 Return a temporal point sequence split into temporal float sequences for each of its coordinates (iterator function) More...
 
TSequenceSettpointseqset_azimuth (const TSequenceSet *ss)
 Return the temporal azimuth of a temporal geometry point sequence set. More...
 
TSequenceSettpointseqset_cumulative_length (const TSequenceSet *ss)
 Return the cumulative length traversed by a temporal point sequence set. More...
 
static GSERIALIZEDtpointseqset_decouple (const TSequenceSet *ss, int64 **timesarr, int *count)
 Decouple the points and the timestamptz values of a temporal point sequence set. More...
 
bool tpointseqset_direction (const TSequenceSet *ss, double *result)
 Return the direction of a temporal point sequence set. More...
 
static TSequenceSettpointseqset_grid (const TSequenceSet *ss, const gridspec *grid, bool filter_pts)
 Return a temporal point sequence set snapped to a grid specification. More...
 
bool tpointseqset_is_simple (const TSequenceSet *ss)
 Return true if a temporal point does not self-intersect. More...
 
double tpointseqset_length (const TSequenceSet *ss)
 Return the length traversed by a temporal point sequence set. More...
 
GSERIALIZEDtpointseqset_linear_trajectory (const TSequenceSet *ss, bool unary_union)
 Return the trajectory of a temporal point sequence set. More...
 
TSequence ** tpointseqset_make_simple (const TSequenceSet *ss, int *count)
 Return a temporal point sequence set split into an array of non self-intersecting fragments. More...
 
static TSequenceSettpointseqset_remove_repeated_points (const TSequenceSet *ss, double tolerance, int min_points)
 Return a temporal point with consecutive equal points removed. More...
 
TSequenceSettpointseqset_speed (const TSequenceSet *ss)
 Return the speed of a temporal point sequence set. More...
 
static GSERIALIZEDtpointseqset_to_geomeas (const TSequenceSet *ss, const TSequenceSet *meas)
 Return a geometry/geography with M measure from a temporal point sequence set and optionally a temporal float. More...
 
static GSERIALIZEDtpointseqset_to_geomeas_segm (const TSequenceSet *ss, const TSequenceSet *meas)
 Return a geometry/geography with M measure from a temporal point sequence set and optionally a temporal float. More...
 
GSERIALIZEDtpointseqset_twcentroid (const TSequenceSet *ss)
 Return the time-weighed centroid of a temporal geometry point sequence set. More...
 

Variables

enum { ... }  MEOS_SEG_INTER_TYPE
 

Detailed Description

Spatial functions for temporal points.