PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ geography_shortestline()

Datum geography_shortestline ( PG_FUNCTION_ARGS  )

Definition at line 1443 of file geography_measurement.c.

1444 {
1445  GSERIALIZED* g1 = PG_GETARG_GSERIALIZED_P(0);
1446  GSERIALIZED* g2 = PG_GETARG_GSERIALIZED_P(1);
1447  bool use_spheroid = PG_GETARG_BOOL(2);
1448  LWGEOM *line, *lwgeom1, *lwgeom2;
1450  SPHEROID s;
1451 
1452  gserialized_error_if_srid_mismatch(g1, g2, __func__);
1453 
1454  lwgeom1 = lwgeom_from_gserialized(g1);
1455  lwgeom2 = lwgeom_from_gserialized(g2);
1456 
1457  /* Return NULL on empty/bad arguments. */
1458  if ( !lwgeom1 || !lwgeom2 || lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
1459  {
1460  PG_FREE_IF_COPY(g1, 0);
1461  PG_FREE_IF_COPY(g2, 1);
1462  PG_RETURN_NULL();
1463  }
1464 
1465  /* Initialize spheroid */
1466  spheroid_init_from_srid(gserialized_get_srid(g1), &s);
1467 
1468  /* Set to sphere if requested */
1469  if ( ! use_spheroid )
1470  s.a = s.b = s.radius;
1471 
1472  line = geography_tree_shortestline(lwgeom1, lwgeom2, FP_TOLERANCE, &s);
1473 
1474  if (lwgeom_is_empty(line))
1475  PG_RETURN_NULL();
1476 
1477  result = geography_serialize(line);
1478  lwgeom_free(line);
1479 
1480  PG_FREE_IF_COPY(g1, 0);
1481  PG_FREE_IF_COPY(g2, 1);
1482  PG_RETURN_POINTER(result);
1483 }
char * s
Definition: cu_in_wkt.c:23
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
Definition: gserialized.c:432
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized.c:155
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
#define FP_TOLERANCE
Floating point comparators.
LWGEOM * geography_tree_shortestline(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2, double threshold, const SPHEROID *spheroid)
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:199

References FP_TOLERANCE, geography_tree_shortestline(), gserialized_error_if_srid_mismatch(), gserialized_get_srid(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), result, and s.

Here is the call graph for this function: