PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ geography_shortestline()

Datum geography_shortestline ( PG_FUNCTION_ARGS  )

Definition at line 1446 of file geography_measurement.c.

1447 {
1448  GSERIALIZED* g1 = PG_GETARG_GSERIALIZED_P(0);
1449  GSERIALIZED* g2 = PG_GETARG_GSERIALIZED_P(1);
1450  bool use_spheroid = PG_GETARG_BOOL(2);
1451  LWGEOM *line, *lwgeom1, *lwgeom2;
1453  SPHEROID s;
1454 
1455  gserialized_error_if_srid_mismatch(g1, g2, __func__);
1456 
1457  lwgeom1 = lwgeom_from_gserialized(g1);
1458  lwgeom2 = lwgeom_from_gserialized(g2);
1459 
1460  /* Return NULL on empty/bad arguments. */
1461  if ( !lwgeom1 || !lwgeom2 || lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
1462  {
1463  PG_FREE_IF_COPY(g1, 0);
1464  PG_FREE_IF_COPY(g2, 1);
1465  PG_RETURN_NULL();
1466  }
1467 
1468  /* Initialize spheroid */
1469  spheroid_init_from_srid(gserialized_get_srid(g1), &s);
1470 
1471  /* Set to sphere if requested */
1472  if ( ! use_spheroid )
1473  s.a = s.b = s.radius;
1474 
1475  line = geography_tree_shortestline(lwgeom1, lwgeom2, FP_TOLERANCE, &s);
1476 
1477  if (lwgeom_is_empty(line))
1478  PG_RETURN_NULL();
1479 
1480  result = geography_serialize(line);
1481  lwgeom_free(line);
1482 
1483  PG_FREE_IF_COPY(g1, 0);
1484  PG_FREE_IF_COPY(g2, 1);
1485  PG_RETURN_POINTER(result);
1486 }
char * s
Definition: cu_in_wkt.c:23
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
void gserialized_error_if_srid_mismatch(const GSERIALIZED *g1, const GSERIALIZED *g2, const char *funcname)
Definition: gserialized.c:403
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:126
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
#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:203

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: