PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ pointonsurface()

Datum pointonsurface ( PG_FUNCTION_ARGS  )

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

1280 {
1281  GSERIALIZED *geom;
1282  GEOSGeometry *g1, *g3;
1283  GSERIALIZED *result;
1284 
1285  geom = PG_GETARG_GSERIALIZED_P(0);
1286 
1287  /* Empty.PointOnSurface == Point Empty */
1288  if ( gserialized_is_empty(geom) )
1289  {
1291  gserialized_get_srid(geom),
1292  gserialized_has_z(geom),
1293  gserialized_has_m(geom));
1294  result = geometry_serialize(lwpoint_as_lwgeom(lwp));
1295  lwpoint_free(lwp);
1296  PG_RETURN_POINTER(result);
1297  }
1298 
1299  initGEOS(lwpgnotice, lwgeom_geos_error);
1300 
1301  g1 = POSTGIS2GEOS(geom);
1302 
1303  if (!g1)
1304  {
1305  /* Why is this a WARNING rather than an error ? */
1306  /* TODO: use HANDLE_GEOS_ERROR instead */
1307  elog(WARNING, "GEOSPointOnSurface(): %s", lwgeom_geos_errmsg);
1308  PG_RETURN_NULL();
1309  }
1310 
1311  g3 = GEOSPointOnSurface(g1);
1312 
1313  if (!g3)
1314  {
1315  GEOSGeom_destroy(g1);
1316  HANDLE_GEOS_ERROR("GEOSPointOnSurface");
1317  }
1318 
1319  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
1320 
1321  GEOSSetSRID(g3, gserialized_get_srid(geom));
1322 
1323  result = GEOS2POSTGIS(g3, gserialized_has_z(geom));
1324 
1325  if (!result)
1326  {
1327  GEOSGeom_destroy(g1);
1328  GEOSGeom_destroy(g3);
1329  elog(ERROR,"GEOS pointonsurface() threw an error (result postgis geometry formation)!");
1330  PG_RETURN_NULL(); /* never get here */
1331  }
1332 
1333  GEOSGeom_destroy(g1);
1334  GEOSGeom_destroy(g3);
1335 
1336  PG_FREE_IF_COPY(geom, 0);
1337 
1338  PG_RETURN_POINTER(result);
1339 }
int gserialized_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
Definition: g_serialized.c:50
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:45
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:178
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:335
#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:99
Here is the call graph for this function:
Here is the caller graph for this function: