MobilityDB 1.3
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
postgis_funcs.c File Reference

Functions for geometry/geography types corresponding to external PostGIS functions in order to bypass the function manager in fmgr.c. More...

#include "geo/postgis_funcs.h"
#include <assert.h>
#include <float.h>
#include <geos_c.h>
#include <liblwgeom.h>
#include <lwgeom_log.h>
#include <intervaltree.h>
#include <lwgeom_geos.h>
#include <meos.h>
#include <meos_internal.h>
#include "temporal/postgres_types.h"
#include "temporal/type_util.h"
#include "geo/meos_transform.h"
#include "geo/tgeo.h"
#include "geo/tgeo_spatialfuncs.h"

Data Structures

struct  Circle
 Definition of the 2D circle structure. More...
 

Macros

#define MAXBOX3DLEN   255
 
#define MAXGBOXLEN   255
 
#define PG_PARSER_ERROR(lwg_parser_result)
 
#define PGIS_FP_TOLERANCE   1e-12
 

Functions

LWGEOMbox2d_to_lwgeom (GBOX *box, int32_t srid)
 Create a geometry from a BOX2D. More...
 
BOX3Dbox3d_make (double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, int32 srid)
 Return a PostGIS BOX3D from the arguments. More...
 
char * box3d_out (const BOX3D *box, int maxdd)
 Return the string representation of a PostGIS BOX3D. More...
 
LWGEOMbox3d_to_lwgeom (BOX3D *box)
 Create a geometry from a BOX3D. More...
 
LWPOINTcart_to_lwpoint (const double_t x_sum, const double_t y_sum, const double_t z_sum, const double_t weight_sum, const int32_t srid)
 
static double distance_point2d (POINT2D a, POINT2D b)
 Return the distance between two points. More...
 
GBOXgbox_make (bool hasz, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax)
 Return a PostGIS GBOX from the arguments. More...
 
char * gbox_out (const GBOX *box, int maxdd)
 Return the string representation of a PostGIS GBOX. More...
 
uint8_t * geo_as_ewkb (const GSERIALIZED *gs, const char *endian, size_t *size)
 Return the Extended Well-Known Binary (EWKB) representation of a geometry/geography. More...
 
char * geo_as_ewkt (const GSERIALIZED *gs, int precision)
 Return the Extended Well-Known Text (EWKT) representation of a geometry/geography. More...
 
char * geo_as_geojson (const GSERIALIZED *gs, int option, int precision, const char *srs)
 Return the GeoJSON representation of a geometry/geography. More...
 
char * geo_as_hexewkb (const GSERIALIZED *gs, const char *endian)
 Return the ASCII hex-encoded Well-Known Binary (HexWKB) representation of a geometry/geography. More...
 
char * geo_as_text (const GSERIALIZED *gs, int precision)
 Return the Well-Known Text (WKT) representation of a geometry/geography. More...
 
char * geo_as_wkt (const GSERIALIZED *gs, int precision, bool extended)
 Return the (Extended) Well-Known Text (EWKT or WKT) representation of a geometry/geography. More...
 
GSERIALIZEDgeo_collect_garray (GSERIALIZED **gsarr, int nelems)
 Collect the array of geometries/geographies into a geo collection. More...
 
GSERIALIZEDgeo_copy (const GSERIALIZED *gs)
 Return a copy of a geometry. More...
 
int geo_equals (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return true if the geometries/geographies are equal, false otherwise. More...
 
GSERIALIZED ** geo_extract_elements (const GSERIALIZED *gs, int *count)
 Extract the first-level elements of a gemetry collection. More...
 
GSERIALIZEDgeo_from_ewkb (const uint8_t *wkb, size_t wkb_size, int32 srid)
 Return a geometry/geography from its EWKB representation. More...
 
GSERIALIZEDgeo_from_geojson (const char *geojson)
 Return a geometry/geography from its GeoJSON representation. More...
 
GSERIALIZEDgeo_from_text (const char *wkt, int32_t srid)
 Return a geometry/geography from its WKT representation (and optionally a SRID) More...
 
GSERIALIZEDgeo_geo_n (const GSERIALIZED *gs, int n)
 Return a copy of the n-th composing geometry of a geometry. More...
 
bool geo_is_empty (const GSERIALIZED *gs)
 Get the SRID of a geometry/geography. More...
 
bool geo_is_unitary (const GSERIALIZED *gs)
 
GSERIALIZEDgeo_makeline_garray (GSERIALIZED **gsarr, int count)
 Return a line from an array of geometries/geographies. More...
 
int geo_num_geos (const GSERIALIZED *gs)
 Return the number of composing geometries of a geometry. More...
 
int geo_num_points (const GSERIALIZED *gs)
 Return the number of points of a geometry. More...
 
char * geo_out (const GSERIALIZED *gs)
 Return the ASCII hex-encoded Well-Known Binary (HexWKB) representation of a geometry/geography. More...
 
GSERIALIZED ** geo_pointarr (const GSERIALIZED *gs, int *count)
 Return a point array containing all the coordinates of a geometry. More...
 
GSERIALIZEDgeo_points (const GSERIALIZED *gs)
 Return a MultiPoint containing all the coordinates of a geometry. More...
 
GSERIALIZEDgeo_reverse (const GSERIALIZED *gs)
 Reverse vertex order of a geometry. More...
 
bool geo_same (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return true if the geometries/geographies are the same. More...
 
GSERIALIZEDgeo_serialize (const LWGEOM *geom)
 Serialize a geometry/geography. More...
 
GSERIALIZEDgeo_set_srid (const GSERIALIZED *gs, int32_t srid)
 Set the SRID of a geometry/geography. More...
 
int32_t geo_srid (const GSERIALIZED *gs)
 Get the SRID of a geometry/geography. More...
 
GSERIALIZEDgeo_transform (const GSERIALIZED *gs, int32_t srid_to)
 Return the geometry/geography transformed to an SRID. More...
 
GSERIALIZEDgeo_transform_pipeline (const GSERIALIZED *gs, char *pipeline, int32_t srid_to, bool is_forward)
 Return a geometry/geography transformed to another SRID using a pipeline. More...
 
const char * geo_typename (int type)
 Return a string representation of a geometry's type. More...
 
double geog_area (const GSERIALIZED *gs, bool use_spheroid)
 Return the area of a geography in square meters. More...
 
GSERIALIZEDgeog_centroid (const GSERIALIZED *g, bool use_spheroid)
 Return the centroid of a geometry. More...
 
double geog_distance (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return the distance between two geographies. More...
 
bool geog_dwithin (const GSERIALIZED *gs1, const GSERIALIZED *gs2, double tolerance, bool use_spheroid)
 Return true if two geographies are within a distance. More...
 
GSERIALIZEDgeog_from_hexewkb (const char *wkt)
 Return a geography from its ASCII hex-encoded Well-Known Binary (HexEWKB) representation. More...
 
GSERIALIZEDgeog_from_lwgeom (LWGEOM *lwgeom, int32 typmod)
 Return a geography from a LWGEOM. More...
 
GSERIALIZEDgeog_in (const char *str, int32 typmod)
 Return a geography from its Well-Known Text or Binary (WKT or Binary) representation. More...
 
bool geog_intersects (const GSERIALIZED *gs1, const GSERIALIZED *gs2, bool use_spheroid)
 Return true if the geographies intersect. More...
 
double geog_length (const GSERIALIZED *gs, bool use_spheroid)
 Return double length in meters. More...
 
double geog_perimeter (const GSERIALIZED *gs, bool use_spheroid)
 Return the perimeter of a geography in meters. More...
 
GSERIALIZEDgeog_serialize (LWGEOM *lwgeom)
 Utility method to call the serialization and then set the PgSQL varsize header appropriately with the serialized size. More...
 
GSERIALIZEDgeog_to_geom (const GSERIALIZED *gs)
 Return a geometry from a geography. More...
 
GSERIALIZEDgeogpoint_make2d (int32_t srid, double x, double y)
 Return a 2D geography point constructed from the arguments. More...
 
GSERIALIZEDgeogpoint_make3dz (int32_t srid, double x, double y, double z)
 Return a 3DZ geography point constructed from the arguments. More...
 
LWPOINTgeography_centroid_from_mline (const LWMLINE *mline, SPHEROID *s)
 Split lines into segments and calculate with middle of segment as weighted point. More...
 
LWPOINTgeography_centroid_from_mpoly (const LWMPOLY *mpoly, bool use_spheroid, SPHEROID *s)
 Split polygons into triangles and use centroid of the triangle with the triangle area as weight to calculate the centroid of a (multi)polygon. More...
 
LWPOINTgeography_centroid_from_wpoints (const int32_t srid, const POINT3DM *points, const uint32_t size)
 Convert lat-lon-points to x-y-z-coordinates, calculate a weighted average point and return lat-lon-coordinated. More...
 
void geography_valid_type (uint8_t type)
 Ensure that the geography type is valid The geography type only support POINT, LINESTRING, POLYGON, MULTI* variants of same, and GEOMETRYCOLLECTION. More...
 
GSERIALIZEDgeom_array_union (GSERIALIZED **gsarr, int count)
 Return the union of an array of geometries. More...
 
bool geom_azimuth (const GSERIALIZED *gs1, const GSERIALIZED *gs2, double *result)
 Return in the last argument the azimuth of a segment defined by two points. More...
 
GSERIALIZEDgeom_boundary (const GSERIALIZED *gs)
 Return the boundary of a geometry. More...
 
GSERIALIZEDgeom_buffer (const GSERIALIZED *gs, double size, const char *params)
 Return a POLYGON or a MULTIPOLYGON that represents all points whose distance from a geometry/geography is less than or equal to a given distance. More...
 
GSERIALIZEDgeom_centroid (const GSERIALIZED *gs)
 Return the centroid of a geometry. More...
 
bool geom_contains (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return true if the first geometry contains the second one. More...
 
GSERIALIZEDgeom_convex_hull (const GSERIALIZED *gs)
 Return the convex hull of the geometry. More...
 
bool geom_covers (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return true if the first geometry covers the second one. More...
 
GSERIALIZEDgeom_difference2d (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return the difference of two geometries. More...
 
bool geom_disjoint2d (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return true if two geometries are disjoint in 2D. More...
 
double geom_distance2d (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return the distance between two geometries. More...
 
double geom_distance3d (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return the 3D distance between two geometries. More...
 
bool geom_dwithin2d (const GSERIALIZED *gs1, const GSERIALIZED *gs2, double tolerance)
 Return true if two geometries are within a distance. More...
 
bool geom_dwithin3d (const GSERIALIZED *gs1, const GSERIALIZED *gs2, double tolerance)
 Return true if two geometries are within a distance. More...
 
GSERIALIZEDgeom_from_hexewkb (const char *wkt)
 Return a geometry from its ASCII hex-encoded Well-Known Binary (HexEWKB) representation. More...
 
GSERIALIZEDgeom_in (const char *str, int32 typmod)
 Return a geometry from its Well-Known Text (WKT), Well-Known Binary (WKB) or GeoJSON representation. More...
 
GSERIALIZEDgeom_intersection2d (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return the intersection of two geometries. More...
 
GSERIALIZEDgeom_intersection2d_coll (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Call function geom_intersection2d for each element of the collection if the arguments are collections. More...
 
bool geom_intersects2d (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return true if two geometries intersects. More...
 
bool geom_intersects3d (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return true if the 3D geometries intersect. More...
 
double geom_length (const GSERIALIZED *gs)
 Return the length of a geometry. More...
 
GSERIALIZEDgeom_min_bounding_radius (const GSERIALIZED *geom, double *radius)
 Return the center point and radius of the smallest circle that contains a geometry. More...
 
double geom_perimeter (const GSERIALIZED *gs)
 Return the perimeter of a geometry. More...
 
bool geom_relate_pattern (const GSERIALIZED *gs1, const GSERIALIZED *gs2, char *p)
 Return true if two geometries satisfy a spatial relationship given by a pattern. More...
 
GSERIALIZEDgeom_serialize (LWGEOM *lwgeom)
 Utility method to call the serialization and then set the PgSQL varsize header appropriately with the serialized size. More...
 
GSERIALIZEDgeom_shortestline2d (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return the shortest 2D line between two geometries. More...
 
GSERIALIZEDgeom_shortestline3d (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return the shortest line between two 3D geometries. More...
 
bool geom_spatialrel (const GSERIALIZED *gs1, const GSERIALIZED *gs2, spatialRel rel)
 Return true if two geometries satisfy a given spatial relationship, where the function called depend on the third argument. More...
 
GSERIALIZEDgeom_to_geog (const GSERIALIZED *gs)
 Return a geography from a geometry. More...
 
bool geom_touches (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Return true if the two geometries intersect on a border. More...
 
GSERIALIZEDgeom_unary_union (const GSERIALIZED *gs, double prec)
 Return the unary union of a geometry. More...
 
GSERIALIZEDgeompoint_make2d (int32_t srid, double x, double y)
 Return a 2D geometry point constructed from the arguments. More...
 
GSERIALIZEDgeompoint_make3dz (int32_t srid, double x, double y, double z)
 Return a 3DZ geometry point constructed from the arguments. More...
 
GSERIALIZEDGEOS2POSTGIS (GEOSGeom geom, char want3d)
 Tranform a GEOS geometry to a PostGIS one. More...
 
static char gserialized_is_point (const GSERIALIZED *gs)
 Return true if a geometry is a point. More...
 
static char gserialized_is_poly (const GSERIALIZED *gs)
 Return true if a geometry is a polygon. More...
 
bool itree_pip_contains (const IntervalTree *itree, const LWGEOM *lwpoints)
 
bool itree_pip_covers (const IntervalTree *itree, const LWGEOM *lwpoints)
 
bool itree_pip_intersects (const IntervalTree *itree, const LWGEOM *lwpoints)
 
GSERIALIZEDline_interpolate_point (const GSERIALIZED *gs, double fraction, bool repeat)
 Interpolate one or several points from a line. More...
 
double line_locate_point (const GSERIALIZED *gs1, const GSERIALIZED *gs2)
 Locate a point into a line. More...
 
int line_numpoints (const GSERIALIZED *gs)
 Return the number of points of a line. More...
 
GSERIALIZEDline_point_n (const GSERIALIZED *gs, int n)
 Return the n-th point of a line. More...
 
GSERIALIZEDline_substring (const GSERIALIZED *gs, double from, double to)
 Return a subline from a line. More...
 
POINT3Dlonlat_to_cart (const double_t raw_lon, const double_t raw_lat)
 
static void lwgeom_collect_points (const LWGEOM *geom, MeosArray *array)
 Extract coordinates from LWGEOM. More...
 
LWGEOMlwgeom_line_interpolate_point (LWGEOM *lwgeom, double fraction, int32_t srid, char repeat)
 Interpolate a point from a line. More...
 
static Circle lwgeom_mec (const LWGEOM *geom)
 Computation of the Minimum Enclosing Circle. More...
 
static bool lwgeom_mec_supported_type (const LWGEOM *geom)
 Return true if the geometry type is one of the supported types for the MEOS fast Minimum Bounding Circle. More...
 
static Circle mec_circle2 (POINT2D a, POINT2D b)
 Circle constructor for 2 points. More...
 
static Circle mec_circle3 (POINT2D a, POINT2D b, POINT2D c)
 Circle constructor for 3 points. More...
 
static Circle mec_circle3_safe (POINT2D a, POINT2D b, POINT2D c)
 Return the minimum enclosing circle for 3 points, handling the collinear case by falling back to the best 2-point circle. More...
 
static bool mec_inside (POINT2D p, Circle c)
 Return true if a point is inside a circle. More...
 
static Circle mec_welzl (POINT2D *P, int n)
 Iterative Welzl algorithm for the minimum enclosing circle. More...
 
static char meos_call_geos2 (const GSERIALIZED *gs1, const GSERIALIZED *gs2, char(*func)(const GEOSGeometry *geos1, const GEOSGeometry *geos2))
 Transform two GSERIALIZED geometries into GEOSGeometry and call the GEOS function passed as argument. More...
 
static bool meos_point_in_polygon (const GSERIALIZED *gs1, const GSERIALIZED *gs2, spatialRel rel)
 Return -1, 0, or 1 depending on whether a (multi)point is completely outside, on the boundary, or completely inside a (multi)polygon. More...
 
GEOSGeometry * POSTGIS2GEOS (const GSERIALIZED *gs)
 Tranform a PostGIS geometry to a GEOS one. More...
 
GSERIALIZEDpostgis_valid_typmod (GSERIALIZED *gs, int32_t typmod)
 Check the consistency of the metadata to enforce in the typmod: SRID, type, and dimensionality. More...
 
int spheroid_init_from_srid (int32_t srid, SPHEROID *s)
 Return 1 if the spheroid in the last argument was initialized from an SRID, return 0 otherwise. More...
 

Variables

static const char * _GEO_TYPENAME []
 Global constant array containing the geometry type strings. More...
 

Detailed Description

Functions for geometry/geography types corresponding to external PostGIS functions in order to bypass the function manager in fmgr.c.