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

Definition at line 595 of file lwgeom_functions_basic.c.

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

596 {
598  GSERIALIZED *geom1 = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
599  GSERIALIZED *geom2 = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
600  LWGEOM *theline;
601  LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
602  LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
603 
604  if (lwgeom1->srid != lwgeom2->srid)
605  {
606  elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
607  PG_RETURN_NULL();
608  }
609 
610  theline = lw_dist2d_distanceline(lwgeom1, lwgeom2, lwgeom1->srid, DIST_MIN);
611 
612  if (lwgeom_is_empty(theline))
613  PG_RETURN_NULL();
614 
615  result = geometry_serialize(theline);
616  lwgeom_free(theline);
617  lwgeom_free(lwgeom1);
618  lwgeom_free(lwgeom2);
619 
620  PG_FREE_IF_COPY(geom1, 0);
621  PG_FREE_IF_COPY(geom2, 1);
622  PG_RETURN_POINTER(result);
623 }
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
LWGEOM * lw_dist2d_distanceline(LWGEOM *lw1, LWGEOM *lw2, int srid, int mode)
Function initializing shortestline and longestline calculations.
Definition: measures.c:44
char ** result
Definition: liblwgeom.h:218
int32_t srid
Definition: liblwgeom.h:355
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: