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

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

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

1691 {
1692  GSERIALIZED *geom1;
1693  LWGEOM *lwgeom;
1694  bool result;
1695  GEOSGeom g1;
1696 #if POSTGIS_GEOS_VERSION < 33
1697  GBOX box1;
1698 #endif
1699 
1700  geom1 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1701 
1702  /* Empty.IsValid() == TRUE */
1703  if ( gserialized_is_empty(geom1) )
1704  PG_RETURN_BOOL(true);
1705 
1706 #if POSTGIS_GEOS_VERSION < 33
1707  /* Short circuit and return FALSE if we have infinite coordinates */
1708  /* GEOS 3.3+ is supposed to handle this stuff OK */
1709  if ( gserialized_get_gbox_p(geom1, &box1) )
1710  {
1711  if ( isinf(box1.xmax) || isinf(box1.ymax) || isinf(box1.xmin) || isinf(box1.ymin) ||
1712  isnan(box1.xmax) || isnan(box1.ymax) || isnan(box1.xmin) || isnan(box1.ymin) )
1713  {
1714  lwnotice("Geometry contains an Inf or NaN coordinate");
1715  PG_RETURN_BOOL(FALSE);
1716  }
1717  }
1718 #endif
1719 
1720  initGEOS(lwnotice, lwgeom_geos_error);
1721 
1722  lwgeom = lwgeom_from_gserialized(geom1);
1723  if ( ! lwgeom )
1724  {
1725  lwerror("unable to deserialize input");
1726  }
1727  g1 = LWGEOM2GEOS(lwgeom);
1728  lwgeom_free(lwgeom);
1729 
1730  if ( ! g1 )
1731  {
1732  /* should we drop the following
1733  * notice now that we have ST_isValidReason ?
1734  */
1736  PG_RETURN_BOOL(FALSE);
1737  }
1738 
1739  result = GEOSisValid(g1);
1740  GEOSGeom_destroy(g1);
1741 
1742  if (result == 2)
1743  {
1744  elog(ERROR,"GEOS isvalid() threw an error!");
1745  PG_RETURN_NULL(); /*never get here */
1746  }
1747 
1748  PG_FREE_IF_COPY(geom1, 0);
1749  PG_RETURN_BOOL(result);
1750 }
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:373
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
double xmax
Definition: liblwgeom.h:249
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom)
char ** result
Definition: liblwgeom.h:218
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:140
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
double ymin
Definition: liblwgeom.h:250
double xmin
Definition: liblwgeom.h:248
void lwgeom_geos_error(const char *fmt,...)
double ymax
Definition: liblwgeom.h:251
#define FALSE
Definition: dbfopen.c:169

Here is the call graph for this function: