PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ geometry_to_point()

Datum geometry_to_point ( PG_FUNCTION_ARGS  )

Definition at line 72 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().

73 {
74  Point *point;
75  LWGEOM *lwgeom;
76  LWPOINT *lwpoint;
77  GSERIALIZED *geom;
78 
79  POSTGIS_DEBUG(2, "geometry_to_point called");
80 
81  if ( PG_ARGISNULL(0) )
82  PG_RETURN_NULL();
83 
84  geom = PG_GETARG_GSERIALIZED_P(0);
85 
86  if ( gserialized_get_type(geom) != POINTTYPE )
87  elog(ERROR, "geometry_to_point only accepts Points");
88 
89  lwgeom = lwgeom_from_gserialized(geom);
90 
91  if ( lwgeom_is_empty(lwgeom) )
92  PG_RETURN_NULL();
93 
94  lwpoint = lwgeom_as_lwpoint(lwgeom);
95 
96  point = (Point*)palloc(sizeof(Point));
97  point->x = lwpoint_get_x(lwpoint);
98  point->y = lwpoint_get_y(lwpoint);
99 
100  lwpoint_free(lwpoint);
101  PG_FREE_IF_COPY(geom,0);
102 
103  PG_RETURN_POINT_P(point);
104 }
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:86
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:129
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:63
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:76
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:1346
Here is the call graph for this function:
Here is the caller graph for this function: