PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ isvalid()

Datum isvalid ( PG_FUNCTION_ARGS  )

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

1530 {
1531  GSERIALIZED *geom1;
1532  LWGEOM *lwgeom;
1533  bool result;
1534  GEOSGeom g1;
1535 
1536  geom1 = PG_GETARG_GSERIALIZED_P(0);
1537 
1538  /* Empty.IsValid() == TRUE */
1539  if ( gserialized_is_empty(geom1) )
1540  PG_RETURN_BOOL(true);
1541 
1542  initGEOS(lwpgnotice, lwgeom_geos_error);
1543 
1544  lwgeom = lwgeom_from_gserialized(geom1);
1545  if ( ! lwgeom )
1546  {
1547  lwpgerror("unable to deserialize input");
1548  }
1549  g1 = LWGEOM2GEOS(lwgeom, 0);
1550  lwgeom_free(lwgeom);
1551 
1552  if ( ! g1 )
1553  {
1554  /* should we drop the following
1555  * notice now that we have ST_isValidReason ?
1556  */
1557  lwpgnotice("%s", lwgeom_geos_errmsg);
1558  PG_RETURN_BOOL(false);
1559  }
1560 
1561  result = GEOSisValid(g1);
1562  GEOSGeom_destroy(g1);
1563 
1564  if (result == 2)
1565  {
1566  elog(ERROR,"GEOS isvalid() threw an error!");
1567  PG_RETURN_NULL(); /*never get here */
1568  }
1569 
1570  PG_FREE_IF_COPY(geom1, 0);
1571  PG_RETURN_BOOL(result);
1572 }
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: