PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ pointonsurface()

Datum pointonsurface ( PG_FUNCTION_ARGS  )

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

References centroid(), dumpnode::geom, geometry_serialize(), GEOS2POSTGIS(), gserialized_get_srid(), gserialized_has_m(), gserialized_has_z(), gserialized_is_empty(), HANDLE_GEOS_ERROR, lwgeom_geos_errmsg, lwgeom_geos_error(), lwpoint_as_lwgeom(), lwpoint_construct_empty(), lwpoint_free(), PG_FUNCTION_INFO_V1(), and POSTGIS2GEOS().

Referenced by geos_difference().

1452 {
1453  GSERIALIZED *geom;
1454  GEOSGeometry *g1, *g3;
1455  GSERIALIZED *result;
1456 
1457  geom = PG_GETARG_GSERIALIZED_P(0);
1458 
1459  /* Empty.PointOnSurface == Point Empty */
1460  if ( gserialized_is_empty(geom) )
1461  {
1463  gserialized_get_srid(geom),
1464  gserialized_has_z(geom),
1465  gserialized_has_m(geom));
1466  result = geometry_serialize(lwpoint_as_lwgeom(lwp));
1467  lwpoint_free(lwp);
1468  PG_RETURN_POINTER(result);
1469  }
1470 
1471  initGEOS(lwpgnotice, lwgeom_geos_error);
1472 
1473  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom);
1474 
1475  if ( 0 == g1 ) /* exception thrown at construction */
1476  {
1477  /* Why is this a WARNING rather than an error ? */
1478  /* TODO: use HANDLE_GEOS_ERROR instead */
1479  elog(WARNING, "GEOSPointOnSurface(): %s", lwgeom_geos_errmsg);
1480  PG_RETURN_NULL();
1481  }
1482 
1483  g3 = GEOSPointOnSurface(g1);
1484 
1485  if (g3 == NULL)
1486  {
1487  GEOSGeom_destroy(g1);
1488  HANDLE_GEOS_ERROR("GEOSPointOnSurface");
1489  PG_RETURN_NULL(); /* never get here */
1490  }
1491 
1492  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
1493 
1494  GEOSSetSRID(g3, gserialized_get_srid(geom));
1495 
1496  result = GEOS2POSTGIS(g3, gserialized_has_z(geom));
1497 
1498  if (result == NULL)
1499  {
1500  GEOSGeom_destroy(g1);
1501  GEOSGeom_destroy(g3);
1502  elog(ERROR,"GEOS pointonsurface() threw an error (result postgis geometry formation)!");
1503  PG_RETURN_NULL(); /* never get here */
1504  }
1505 
1506  GEOSGeom_destroy(g1);
1507  GEOSGeom_destroy(g3);
1508 
1509  PG_FREE_IF_COPY(geom, 0);
1510 
1511  PG_RETURN_POINTER(result);
1512 }
int gserialized_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
Definition: g_serialized.c:29
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:182
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:120
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:24
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:139
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
#define HANDLE_GEOS_ERROR(label)
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:69
Here is the call graph for this function:
Here is the caller graph for this function: