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

Definition at line 1521 of file postgis/lwgeom_geos.c.

References geometry_serialize(), GEOS2POSTGIS(), gserialized_get_srid(), gserialized_has_m(), gserialized_has_z(), gserialized_is_empty(), lwerror(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwnotice(), lwpoint_as_lwgeom(), lwpoint_construct_empty(), lwpoint_free(), POSTGIS2GEOS(), and result.

1522 {
1523  GSERIALIZED *geom;
1524  GEOSGeometry *g1, *g3;
1526 
1527  geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1528 
1529  /* Empty.PointOnSurface == Point Empty */
1530  if ( gserialized_is_empty(geom) )
1531  {
1533  gserialized_get_srid(geom),
1534  gserialized_has_z(geom),
1535  gserialized_has_m(geom));
1536  result = geometry_serialize(lwpoint_as_lwgeom(lwp));
1537  lwpoint_free(lwp);
1538  PG_RETURN_POINTER(result);
1539  }
1540 
1541  initGEOS(lwnotice, lwgeom_geos_error);
1542 
1543  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom);
1544 
1545  if ( 0 == g1 ) /* exception thrown at construction */
1546  {
1547  elog(WARNING, "GEOSPointOnSurface(): %s", lwgeom_geos_errmsg);
1548  PG_RETURN_NULL();
1549  }
1550 
1551  g3 = GEOSPointOnSurface(g1);
1552 
1553  if (g3 == NULL)
1554  {
1555  GEOSGeom_destroy(g1);
1556  lwerror("GEOSPointOnSurface: %s", lwgeom_geos_errmsg);
1557  PG_RETURN_NULL(); /* never get here */
1558  }
1559 
1560  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
1561 
1562  GEOSSetSRID(g3, gserialized_get_srid(geom));
1563 
1564  result = GEOS2POSTGIS(g3, gserialized_has_z(geom));
1565 
1566  if (result == NULL)
1567  {
1568  GEOSGeom_destroy(g1);
1569  GEOSGeom_destroy(g3);
1570  elog(ERROR,"GEOS pointonsurface() threw an error (result postgis geometry formation)!");
1571  PG_RETURN_NULL(); /* never get here */
1572  }
1573 
1574  GEOSGeom_destroy(g1);
1575  GEOSGeom_destroy(g3);
1576 
1577  PG_FREE_IF_COPY(geom, 0);
1578 
1579  PG_RETURN_POINTER(result);
1580 }
int gserialized_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
Definition: g_serialized.c:30
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:180
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:118
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:25
char ** result
Definition: liblwgeom.h:218
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:140
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
LWGEOM * geom
void lwgeom_geos_error(const char *fmt,...)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:254
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:70

Here is the call graph for this function: