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

Definition at line 48 of file geometry_inout.c.

References gserialized_get_type(), lwgeom_as_lwpoint(), lwgeom_from_gserialized(), lwgeom_is_empty(), lwpoint_free(), lwpoint_get_x(), lwpoint_get_y(), POINTTYPE, struct_point::x, and struct_point::y.

49 {
50  Point *point;
51  LWGEOM *lwgeom;
52  LWPOINT *lwpoint;
53  GSERIALIZED *geom;
54 
55  POSTGIS_DEBUG(2, "geometry_to_point called");
56 
57  if ( PG_ARGISNULL(0) )
58  PG_RETURN_NULL();
59 
60  geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
61 
62  if ( gserialized_get_type(geom) != POINTTYPE )
63  elog(ERROR, "geometry_to_point only accepts Points");
64 
65  lwgeom = lwgeom_from_gserialized(geom);
66 
67  if ( lwgeom_is_empty(lwgeom) )
68  PG_RETURN_NULL();
69 
70  lwpoint = lwgeom_as_lwpoint(lwgeom);
71 
72  point = (Point*)palloc(sizeof(Point));
73  point->x = lwpoint_get_x(lwpoint);
74  point->y = lwpoint_get_y(lwpoint);
75 
76  lwpoint_free(lwpoint);
77  PG_FREE_IF_COPY(geom,0);
78 
79  PG_RETURN_POINT_P(point);
80 }
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.
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:180
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:80
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:48
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:58
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: