PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ geometry_distance_spheroid()

Datum geometry_distance_spheroid ( PG_FUNCTION_ARGS  )

Definition at line 482 of file lwgeom_spheroid.c.

483{
484 GSERIALIZED *geom1 = PG_GETARG_GSERIALIZED_P(0);
485 GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
486 SPHEROID *sphere = (SPHEROID *)PG_GETARG_POINTER(2);
487 int type1 = gserialized_get_type(geom1);
488 int type2 = gserialized_get_type(geom2);
489 bool use_spheroid = PG_GETARG_BOOL(3);
490 LWGEOM *lwgeom1, *lwgeom2;
491 double distance;
492 gserialized_error_if_srid_mismatch(geom1, geom2, __func__);
493
494 /* Calculate some other parameters on the spheroid */
495 spheroid_init(sphere, sphere->a, sphere->b);
496
497 /* Catch sphere special case and re-jig spheroid appropriately */
498 if ( ! use_spheroid )
499 {
500 sphere->a = sphere->b = sphere->radius;
501 }
502
503 if ( ! ( type1 == POINTTYPE || type1 == LINETYPE || type1 == POLYGONTYPE ||
504 type1 == MULTIPOINTTYPE || type1 == MULTILINETYPE || type1 == MULTIPOLYGONTYPE ))
505 {
506 elog(ERROR, "geometry_distance_spheroid: Only point/line/polygon supported.\n");
507 PG_RETURN_NULL();
508 }
509
510 if ( ! ( type2 == POINTTYPE || type2 == LINETYPE || type2 == POLYGONTYPE ||
511 type2 == MULTIPOINTTYPE || type2 == MULTILINETYPE || type2 == MULTIPOLYGONTYPE ))
512 {
513 elog(ERROR, "geometry_distance_spheroid: Only point/line/polygon supported.\n");
514 PG_RETURN_NULL();
515 }
516
517 /* Get #LWGEOM structures */
518 lwgeom1 = lwgeom_from_gserialized(geom1);
519 lwgeom2 = lwgeom_from_gserialized(geom2);
520
521 /* We are going to be calculating geodetic distances */
524 lwgeom_refresh_bbox(lwgeom1);
525 lwgeom_refresh_bbox(lwgeom2);
526
527 distance = lwgeom_distance_spheroid(lwgeom1, lwgeom2, sphere, 0.0);
528
529 PG_RETURN_FLOAT8(distance);
530
531}
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition lwgeom.c:735
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition lwgeom.c:992
double lwgeom_distance_spheroid(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, const SPHEROID *spheroid, double tolerance)
Calculate the geodetic distance from lwgeom1 to lwgeom2 on the spheroid.
#define MULTILINETYPE
Definition liblwgeom.h:106
#define LINETYPE
Definition liblwgeom.h:103
#define MULTIPOINTTYPE
Definition liblwgeom.h:105
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition liblwgeom.h:102
#define MULTIPOLYGONTYPE
Definition liblwgeom.h:107
#define POLYGONTYPE
Definition liblwgeom.h:104
void spheroid_init(SPHEROID *s, double a, double b)
Initialize a spheroid object for use in geodetic functions.
Definition lwspheroid.c:39
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:93
static double distance(double x1, double y1, double x2, double y2)
Definition lwtree.c:1032
double radius
Definition liblwgeom.h:380
double a
Definition liblwgeom.h:375
double b
Definition liblwgeom.h:376

References SPHEROID::a, SPHEROID::b, distance(), gserialized_error_if_srid_mismatch(), gserialized_get_type(), LINETYPE, LW_TRUE, lwgeom_distance_spheroid(), lwgeom_from_gserialized(), lwgeom_refresh_bbox(), lwgeom_set_geodetic(), MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, POINTTYPE, POLYGONTYPE, SPHEROID::radius, and spheroid_init().

Referenced by LWGEOM_distance_ellipsoid(), and LWGEOM_distance_sphere().

Here is the call graph for this function:
Here is the caller graph for this function: