PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum LWGEOM_closestpoint ( PG_FUNCTION_ARGS  )

Definition at line 609 of file lwgeom_functions_basic.c.

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

610 {
611  GSERIALIZED *result;
612  GSERIALIZED *geom1 = PG_GETARG_GSERIALIZED_P(0);
613  GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
614  LWGEOM *point;
615  LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
616  LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
617 
618  error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
619 
620  point = lwgeom_closest_point(lwgeom1, lwgeom2);
621 
622  if (lwgeom_is_empty(point))
623  PG_RETURN_NULL();
624 
625  result = geometry_serialize(point);
626  lwgeom_free(point);
627  lwgeom_free(lwgeom1);
628  lwgeom_free(lwgeom2);
629 
630  PG_FREE_IF_COPY(geom1, 0);
631  PG_FREE_IF_COPY(geom2, 1);
632  PG_RETURN_POINTER(result);
633 }
LWGEOM * lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2)
Definition: measures.c:54
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:338
int32_t srid
Definition: liblwgeom.h:398
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
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:1386

Here is the call graph for this function: