PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ geometry_to_point()

Datum geometry_to_point ( PG_FUNCTION_ARGS  )

Definition at line 48 of file geometry_inout.c.

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

Referenced by point_to_geometry().

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 = PG_GETARG_GSERIALIZED_P(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:55
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:182
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:80
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:50
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c: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:1297
Here is the call graph for this function:
Here is the caller graph for this function: