PostGIS  2.2.7dev-r@@SVN_REVISION@@
Datum LWGEOM_shortestline2d ( PG_FUNCTION_ARGS  )

Definition at line 623 of file lwgeom_functions_basic.c.

References error_if_srid_mismatch(), geometry_serialize(), lwgeom_closest_line(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), and LWGEOM::srid.

624 {
625  GSERIALIZED *result;
626  GSERIALIZED *geom1 = PG_GETARG_GSERIALIZED_P(0);
627  GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
628  LWGEOM *theline;
629  LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
630  LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
631 
632  error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
633 
634  theline = lwgeom_closest_line(lwgeom1, lwgeom2);
635 
636  if (lwgeom_is_empty(theline))
637  PG_RETURN_NULL();
638 
639  result = geometry_serialize(theline);
640  lwgeom_free(theline);
641  lwgeom_free(lwgeom1);
642  lwgeom_free(lwgeom2);
643 
644  PG_FREE_IF_COPY(geom1, 0);
645  PG_FREE_IF_COPY(geom2, 1);
646  PG_RETURN_POINTER(result);
647 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:341
int32_t srid
Definition: liblwgeom.h:383
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWGEOM * lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:28
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1297

Here is the call graph for this function: