PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ pointonsurface()

Datum pointonsurface ( PG_FUNCTION_ARGS  )

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

1285 {
1286  GSERIALIZED *geom;
1287  GEOSGeometry *g1, *g3;
1288  GSERIALIZED *result;
1289 
1290  geom = PG_GETARG_GSERIALIZED_P(0);
1291 
1292  /* Empty.PointOnSurface == Point Empty */
1293  if ( gserialized_is_empty(geom) )
1294  {
1296  gserialized_get_srid(geom),
1297  gserialized_has_z(geom),
1298  gserialized_has_m(geom));
1299  result = geometry_serialize(lwpoint_as_lwgeom(lwp));
1300  lwpoint_free(lwp);
1301  PG_RETURN_POINTER(result);
1302  }
1303 
1304  initGEOS(lwpgnotice, lwgeom_geos_error);
1305 
1306  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom);
1307 
1308  if ( 0 == g1 ) /* exception thrown at construction */
1309  {
1310  /* Why is this a WARNING rather than an error ? */
1311  /* TODO: use HANDLE_GEOS_ERROR instead */
1312  elog(WARNING, "GEOSPointOnSurface(): %s", lwgeom_geos_errmsg);
1313  PG_RETURN_NULL();
1314  }
1315 
1316  g3 = GEOSPointOnSurface(g1);
1317 
1318  if (g3 == NULL)
1319  {
1320  GEOSGeom_destroy(g1);
1321  HANDLE_GEOS_ERROR("GEOSPointOnSurface");
1322  PG_RETURN_NULL(); /* never get here */
1323  }
1324 
1325  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
1326 
1327  GEOSSetSRID(g3, gserialized_get_srid(geom));
1328 
1329  result = GEOS2POSTGIS(g3, gserialized_has_z(geom));
1330 
1331  if (result == NULL)
1332  {
1333  GEOSGeom_destroy(g1);
1334  GEOSGeom_destroy(g3);
1335  elog(ERROR,"GEOS pointonsurface() threw an error (result postgis geometry formation)!");
1336  PG_RETURN_NULL(); /* never get here */
1337  }
1338 
1339  GEOSGeom_destroy(g1);
1340  GEOSGeom_destroy(g3);
1341 
1342  PG_FREE_IF_COPY(geom, 0);
1343 
1344  PG_RETURN_POINTER(result);
1345 }
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:179
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:303
#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:100
Here is the call graph for this function:
Here is the caller graph for this function: