PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ isvalid()

Datum isvalid ( PG_FUNCTION_ARGS  )

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

References FALSE, gserialized_get_gbox_p(), gserialized_is_empty(), isvalidreason(), LWGEOM2GEOS(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_geos_errmsg, lwgeom_geos_error(), PG_FUNCTION_INFO_V1(), GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

Referenced by errorIfGeometryCollection().

1692 {
1693  GSERIALIZED *geom1;
1694  LWGEOM *lwgeom;
1695  bool result;
1696  GEOSGeom g1;
1697 #if POSTGIS_GEOS_VERSION < 33
1698  GBOX box1;
1699 #endif
1700 
1701  geom1 = PG_GETARG_GSERIALIZED_P(0);
1702 
1703  /* Empty.IsValid() == TRUE */
1704  if ( gserialized_is_empty(geom1) )
1705  PG_RETURN_BOOL(true);
1706 
1707 #if POSTGIS_GEOS_VERSION < 33
1708  /* Short circuit and return FALSE if we have infinite coordinates */
1709  /* GEOS 3.3+ is supposed to handle this stuff OK */
1710  if ( gserialized_get_gbox_p(geom1, &box1) )
1711  {
1712  if ( isinf(box1.xmax) || isinf(box1.ymax) || isinf(box1.xmin) || isinf(box1.ymin) ||
1713  isnan(box1.xmax) || isnan(box1.ymax) || isnan(box1.xmin) || isnan(box1.ymin) )
1714  {
1715  lwpgnotice("Geometry contains an Inf or NaN coordinate");
1716  PG_RETURN_BOOL(FALSE);
1717  }
1718  }
1719 #endif
1720 
1721  initGEOS(lwpgnotice, lwgeom_geos_error);
1722 
1723  lwgeom = lwgeom_from_gserialized(geom1);
1724  if ( ! lwgeom )
1725  {
1726  lwpgerror("unable to deserialize input");
1727  }
1728  g1 = LWGEOM2GEOS(lwgeom, 0);
1729  lwgeom_free(lwgeom);
1730 
1731  if ( ! g1 )
1732  {
1733  /* should we drop the following
1734  * notice now that we have ST_isValidReason ?
1735  */
1736  lwpgnotice("%s", lwgeom_geos_errmsg);
1737  PG_RETURN_BOOL(FALSE);
1738  }
1739 
1740  result = GEOSisValid(g1);
1741  GEOSGeom_destroy(g1);
1742 
1743  if (result == 2)
1744  {
1745  elog(ERROR,"GEOS isvalid() threw an error!");
1746  PG_RETURN_NULL(); /*never get here */
1747  }
1748 
1749  PG_FREE_IF_COPY(geom1, 0);
1750  PG_RETURN_BOOL(result);
1751 }
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
Definition: g_serialized.c:371
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
double xmax
Definition: liblwgeom.h:277
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
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:139
double ymin
Definition: liblwgeom.h:278
double xmin
Definition: liblwgeom.h:276
void lwgeom_geos_error(const char *fmt,...)
double ymax
Definition: liblwgeom.h:279
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: