PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ isvalid()

Datum isvalid ( PG_FUNCTION_ARGS  )

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

References gserialized_is_empty(), isvalidreason(), LWGEOM2GEOS(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_geos_errmsg, lwgeom_geos_error(), and PG_FUNCTION_INFO_V1().

Referenced by errorIfGeometryCollection().

1395 {
1396  GSERIALIZED *geom1;
1397  LWGEOM *lwgeom;
1398  char result;
1399  GEOSGeom g1;
1400 
1401  geom1 = PG_GETARG_GSERIALIZED_P(0);
1402 
1403  /* Empty.IsValid() == TRUE */
1404  if ( gserialized_is_empty(geom1) )
1405  PG_RETURN_BOOL(true);
1406 
1407  initGEOS(lwpgnotice, lwgeom_geos_error);
1408 
1409  lwgeom = lwgeom_from_gserialized(geom1);
1410  if ( ! lwgeom )
1411  {
1412  lwpgerror("unable to deserialize input");
1413  }
1414  g1 = LWGEOM2GEOS(lwgeom, 0);
1415  lwgeom_free(lwgeom);
1416 
1417  if ( ! g1 )
1418  {
1419  /* should we drop the following
1420  * notice now that we have ST_isValidReason ?
1421  */
1422  lwpgnotice("%s", lwgeom_geos_errmsg);
1423  PG_RETURN_BOOL(false);
1424  }
1425 
1426  result = GEOSisValid(g1);
1427  GEOSGeom_destroy(g1);
1428 
1429  if (result == 2)
1430  {
1431  elog(ERROR,"GEOS isvalid() threw an error!");
1432  PG_RETURN_NULL(); /*never get here */
1433  }
1434 
1435  PG_FREE_IF_COPY(geom1, 0);
1436  PG_RETURN_BOOL(result);
1437 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:178
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
Here is the call graph for this function:
Here is the caller graph for this function: