PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_length_ellipsoid_linestring()

Datum LWGEOM_length_ellipsoid_linestring ( PG_FUNCTION_ARGS  )

Definition at line 360 of file lwgeom_spheroid.c.

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

Referenced by LWGEOM_length2d_ellipsoid().

361 {
362  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
363  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
364  SPHEROID *sphere = (SPHEROID *) PG_GETARG_POINTER(1);
365  double length = 0.0;
366 
367  /* EMPTY things have no length */
368  if ( lwgeom_is_empty(lwgeom) )
369  {
370  lwgeom_free(lwgeom);
371  PG_RETURN_FLOAT8(0.0);
372  }
373 
374  length = lwgeom_length_spheroid(lwgeom, sphere);
375  lwgeom_free(lwgeom);
376  PG_FREE_IF_COPY(geom, 0);
377 
378  /* Something went wrong... */
379  if ( length < 0.0 )
380  {
381  elog(ERROR, "lwgeom_length_spheroid returned length < 0.0");
382  PG_RETURN_NULL();
383  }
384 
385  /* Clean up */
386  PG_RETURN_FLOAT8(length);
387 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
double lwgeom_length_spheroid(const LWGEOM *geom, const SPHEROID *s)
Calculate the geodetic length of a lwgeom on the unit sphere.
Definition: lwgeodetic.c:3281
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:1346
Here is the call graph for this function:
Here is the caller graph for this function: