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

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

References 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(), and POSTGIS2GEOS().

1239 {
1240  GSERIALIZED *geom;
1241  GEOSGeometry *g1, *g3;
1242  GSERIALIZED *result;
1243 
1244  geom = PG_GETARG_GSERIALIZED_P(0);
1245 
1246  /* Empty.PointOnSurface == Point Empty */
1247  if ( gserialized_is_empty(geom) )
1248  {
1250  gserialized_get_srid(geom),
1251  gserialized_has_z(geom),
1252  gserialized_has_m(geom));
1253  result = geometry_serialize(lwpoint_as_lwgeom(lwp));
1254  lwpoint_free(lwp);
1255  PG_RETURN_POINTER(result);
1256  }
1257 
1258  initGEOS(lwpgnotice, lwgeom_geos_error);
1259 
1260  g1 = POSTGIS2GEOS(geom);
1261 
1262  if (!g1)
1263  {
1264  /* Why is this a WARNING rather than an error ? */
1265  /* TODO: use HANDLE_GEOS_ERROR instead */
1266  elog(WARNING, "GEOSPointOnSurface(): %s", lwgeom_geos_errmsg);
1267  PG_RETURN_NULL();
1268  }
1269 
1270  g3 = GEOSPointOnSurface(g1);
1271 
1272  if (!g3)
1273  {
1274  GEOSGeom_destroy(g1);
1275  HANDLE_GEOS_ERROR("GEOSPointOnSurface");
1276  }
1277 
1278  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
1279 
1280  GEOSSetSRID(g3, gserialized_get_srid(geom));
1281 
1282  result = GEOS2POSTGIS(g3, gserialized_has_z(geom));
1283 
1284  if (!result)
1285  {
1286  GEOSGeom_destroy(g1);
1287  GEOSGeom_destroy(g3);
1288  elog(ERROR,"GEOS pointonsurface() threw an error (result postgis geometry formation)!");
1289  PG_RETURN_NULL(); /* never get here */
1290  }
1291 
1292  GEOSGeom_destroy(g1);
1293  GEOSGeom_destroy(g3);
1294 
1295  PG_FREE_IF_COPY(geom, 0);
1296 
1297  PG_RETURN_POINTER(result);
1298 }
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:334
#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: