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

Definition at line 564 of file lwgeom_ogc.c.

References getPoint2d_p(), gserialized_get_type(), lwerror(), lwgeom_as_lwpoint(), lwgeom_from_gserialized(), lwgeom_is_empty(), LWPOINT::point, POINTTYPE, and POINT2D::x.

565 {
566  GSERIALIZED *geom;
567  LWGEOM *lwgeom;
568  LWPOINT *point = NULL;
569  POINT2D p;
570 
571  geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
572 
573  if ( gserialized_get_type(geom) != POINTTYPE )
574  lwerror("Argument to X() must be a point");
575 
576  lwgeom = lwgeom_from_gserialized(geom);
577  point = lwgeom_as_lwpoint(lwgeom);
578 
579  if ( lwgeom_is_empty(lwgeom) )
580  PG_RETURN_NULL();
581 
582  getPoint2d_p(point->point, 0, &p);
583 
584  PG_FREE_IF_COPY(geom, 0);
585  PG_RETURN_FLOAT8(p.x);
586 }
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
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
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
double x
Definition: liblwgeom.h:284
LWGEOM * geom
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:434
#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: