PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ pointonsurface()

Datum pointonsurface ( PG_FUNCTION_ARGS  )

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

1210 {
1211  GSERIALIZED *geom;
1212  GEOSGeometry *g1, *g3;
1213  GSERIALIZED *result;
1214 
1215  geom = PG_GETARG_GSERIALIZED_P(0);
1216 
1217  /* Empty.PointOnSurface == Point Empty */
1218  if ( gserialized_is_empty(geom) )
1219  {
1221  gserialized_get_srid(geom),
1222  gserialized_has_z(geom),
1223  gserialized_has_m(geom));
1224  result = geometry_serialize(lwpoint_as_lwgeom(lwp));
1225  lwpoint_free(lwp);
1226  PG_RETURN_POINTER(result);
1227  }
1228 
1229  initGEOS(lwpgnotice, lwgeom_geos_error);
1230 
1231  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom);
1232 
1233  if ( 0 == g1 ) /* exception thrown at construction */
1234  {
1235  /* Why is this a WARNING rather than an error ? */
1236  /* TODO: use HANDLE_GEOS_ERROR instead */
1237  elog(WARNING, "GEOSPointOnSurface(): %s", lwgeom_geos_errmsg);
1238  PG_RETURN_NULL();
1239  }
1240 
1241  g3 = GEOSPointOnSurface(g1);
1242 
1243  if (g3 == NULL)
1244  {
1245  GEOSGeom_destroy(g1);
1246  HANDLE_GEOS_ERROR("GEOSPointOnSurface");
1247  PG_RETURN_NULL(); /* never get here */
1248  }
1249 
1250  POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
1251 
1252  GEOSSetSRID(g3, gserialized_get_srid(geom));
1253 
1254  result = GEOS2POSTGIS(g3, gserialized_has_z(geom));
1255 
1256  if (result == NULL)
1257  {
1258  GEOSGeom_destroy(g1);
1259  GEOSGeom_destroy(g3);
1260  elog(ERROR,"GEOS pointonsurface() threw an error (result postgis geometry formation)!");
1261  PG_RETURN_NULL(); /* never get here */
1262  }
1263 
1264  GEOSGeom_destroy(g1);
1265  GEOSGeom_destroy(g3);
1266 
1267  PG_FREE_IF_COPY(geom, 0);
1268 
1269  PG_RETURN_POINTER(result);
1270 }
int gserialized_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
Definition: g_serialized.c:43
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:195
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:133
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:38
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:153
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:267
#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:83
Here is the call graph for this function:
Here is the caller graph for this function: