PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ isvalid()

Datum isvalid ( PG_FUNCTION_ARGS  )

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

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

Referenced by errorIfGeometryCollection().

1542 {
1543  GSERIALIZED *geom1;
1544  LWGEOM *lwgeom;
1545  char result;
1546  GEOSGeom g1;
1547 
1548  geom1 = PG_GETARG_GSERIALIZED_P(0);
1549 
1550  /* Empty.IsValid() == TRUE */
1551  if ( gserialized_is_empty(geom1) )
1552  PG_RETURN_BOOL(true);
1553 
1554  initGEOS(lwpgnotice, lwgeom_geos_error);
1555 
1556  lwgeom = lwgeom_from_gserialized(geom1);
1557  if ( ! lwgeom )
1558  {
1559  lwpgerror("unable to deserialize input");
1560  }
1561  g1 = LWGEOM2GEOS(lwgeom, 0);
1562  lwgeom_free(lwgeom);
1563 
1564  if ( ! g1 )
1565  {
1566  /* should we drop the following
1567  * notice now that we have ST_isValidReason ?
1568  */
1569  lwpgnotice("%s", lwgeom_geos_errmsg);
1570  PG_RETURN_BOOL(FALSE);
1571  }
1572 
1573  result = GEOSisValid(g1);
1574  GEOSGeom_destroy(g1);
1575 
1576  if (result == 2)
1577  {
1578  elog(ERROR,"GEOS isvalid() threw an error!");
1579  PG_RETURN_NULL(); /*never get here */
1580  }
1581 
1582  PG_FREE_IF_COPY(geom1, 0);
1583  PG_RETURN_BOOL(result);
1584 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
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:179
void lwgeom_geos_error(const char *fmt,...)
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, int autofix)
#define FALSE
Definition: dbfopen.c:168
Here is the call graph for this function:
Here is the caller graph for this function: