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

Definition at line 561 of file lwgeom_functions_basic.c.

References DIST_MIN, geometry_serialize(), lw_dist2d_distancepoint(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), result, and LWGEOM::srid.

562 {
564  GSERIALIZED *geom1 = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
565  GSERIALIZED *geom2 = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
566  LWGEOM *point;
567  LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
568  LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
569 
570  if (lwgeom1->srid != lwgeom2->srid)
571  {
572  elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
573  PG_RETURN_NULL();
574  }
575 
576  point = lw_dist2d_distancepoint(lwgeom1, lwgeom2, lwgeom1->srid, DIST_MIN);
577 
578  if (lwgeom_is_empty(point))
579  PG_RETURN_NULL();
580 
581  result = geometry_serialize(point);
582  lwgeom_free(point);
583  lwgeom_free(lwgeom1);
584  lwgeom_free(lwgeom2);
585 
586  PG_FREE_IF_COPY(geom1, 0);
587  PG_FREE_IF_COPY(geom2, 1);
588  PG_RETURN_POINTER(result);
589 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define DIST_MIN
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
char ** result
Definition: liblwgeom.h:218
int32_t srid
Definition: liblwgeom.h:355
LWGEOM * lw_dist2d_distancepoint(LWGEOM *lw1, LWGEOM *lw2, int srid, int mode)
Function initializing closestpoint calculations.
Definition: measures.c:91
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:1229

Here is the call graph for this function: