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

Definition at line 624 of file lwgeom_ogc.c.

References getPoint3dz_p(), gserialized_get_type(), gserialized_has_z(), lwerror(), lwgeom_as_lwpoint(), lwgeom_from_gserialized(), lwgeom_is_empty(), LWPOINT::point, POINTTYPE, and POINT3DZ::z.

625 {
626  GSERIALIZED *geom;
627  LWPOINT *point = NULL;
628  LWGEOM *lwgeom;
629  POINT3DZ p;
630 
631  geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
632 
633  if ( gserialized_get_type(geom) != POINTTYPE )
634  lwerror("Argument to Z() must be a point");
635 
636  lwgeom = lwgeom_from_gserialized(geom);
637  point = lwgeom_as_lwpoint(lwgeom);
638 
639  if ( lwgeom_is_empty(lwgeom) )
640  PG_RETURN_NULL();
641 
642  /* no Z in input */
643  if ( ! gserialized_has_z(geom) ) PG_RETURN_NULL();
644 
645  getPoint3dz_p(point->point, 0, &p);
646 
647  PG_FREE_IF_COPY(geom, 0);
648 
649  PG_RETURN_FLOAT8(p.z);
650 }
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Definition: g_serialized.c:56
double z
Definition: liblwgeom.h:290
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:80
POINTARRAY * point
Definition: liblwgeom.h:367
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:25
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
LWGEOM * geom
int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point)
Definition: lwgeom_api.c:305
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
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: