PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ LWGEOM_x_point()

Datum LWGEOM_x_point ( PG_FUNCTION_ARGS  )

Definition at line 589 of file lwgeom_ogc.c.

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

Referenced by LWGEOM_pointn_linestring().

590 {
591  GSERIALIZED *geom;
592  LWGEOM *lwgeom;
593  LWPOINT *point = NULL;
594  POINT2D p;
595 
596  geom = PG_GETARG_GSERIALIZED_P(0);
597 
598  if ( gserialized_get_type(geom) != POINTTYPE )
599  lwpgerror("Argument to ST_X() must be a point");
600 
601  lwgeom = lwgeom_from_gserialized(geom);
602  point = lwgeom_as_lwpoint(lwgeom);
603 
604  if ( lwgeom_is_empty(lwgeom) )
605  PG_RETURN_NULL();
606 
607  getPoint2d_p(point->point, 0, &p);
608 
609  PG_FREE_IF_COPY(geom, 0);
610  PG_RETURN_FLOAT8(p.x);
611 }
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:69
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:93
POINTARRAY * point
Definition: liblwgeom.h:410
double x
Definition: liblwgeom.h:327
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:461
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
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:1310
Here is the call graph for this function:
Here is the caller graph for this function: