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

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

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

1489 {
1490  GSERIALIZED *geom1;
1491  LWGEOM *lwgeom;
1492  bool result;
1493  GEOSGeom g1;
1494 
1495  geom1 = PG_GETARG_GSERIALIZED_P(0);
1496 
1497  /* Empty.IsValid() == TRUE */
1498  if ( gserialized_is_empty(geom1) )
1499  PG_RETURN_BOOL(true);
1500 
1501  initGEOS(lwpgnotice, lwgeom_geos_error);
1502 
1503  lwgeom = lwgeom_from_gserialized(geom1);
1504  if ( ! lwgeom )
1505  {
1506  lwpgerror("unable to deserialize input");
1507  }
1508  g1 = LWGEOM2GEOS(lwgeom, 0);
1509  lwgeom_free(lwgeom);
1510 
1511  if ( ! g1 )
1512  {
1513  /* should we drop the following
1514  * notice now that we have ST_isValidReason ?
1515  */
1516  lwpgnotice("%s", lwgeom_geos_errmsg);
1517  PG_RETURN_BOOL(false);
1518  }
1519 
1520  result = GEOSisValid(g1);
1521  GEOSGeom_destroy(g1);
1522 
1523  if (result == 2)
1524  {
1525  elog(ERROR,"GEOS isvalid() threw an error!");
1526  PG_RETURN_NULL(); /*never get here */
1527  }
1528 
1529  PG_FREE_IF_COPY(geom1, 0);
1530  PG_RETURN_BOOL(result);
1531 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
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, int autofix)

Here is the call graph for this function: