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

Definition at line 347 of file lwgeom_spheroid.c.

References lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), and lwgeom_length_spheroid().

348 {
349  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
350  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
351  SPHEROID *sphere = (SPHEROID *) PG_GETARG_POINTER(1);
352  double length = 0.0;
353 
354  /* EMPTY things have no length */
355  if ( lwgeom_is_empty(lwgeom) )
356  {
357  lwgeom_free(lwgeom);
358  PG_RETURN_FLOAT8(0.0);
359  }
360 
361  length = lwgeom_length_spheroid(lwgeom, sphere);
362  lwgeom_free(lwgeom);
363  PG_FREE_IF_COPY(geom, 0);
364 
365  /* Something went wrong... */
366  if ( length < 0.0 )
367  {
368  elog(ERROR, "lwgeom_length_spheroid returned length < 0.0");
369  PG_RETURN_NULL();
370  }
371 
372  /* Clean up */
373  PG_RETURN_FLOAT8(length);
374 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:2884
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: