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

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

References gserialized_get_gbox_p(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwnotice(), POSTGIS2GEOS(), GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

1758 {
1759  GSERIALIZED *geom = NULL;
1760  char *reason_str = NULL;
1761  text *result = NULL;
1762  const GEOSGeometry *g1 = NULL;
1763 #if POSTGIS_GEOS_VERSION < 33
1764  GBOX box;
1765 #endif
1766 
1767  geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1768 
1769 #if POSTGIS_GEOS_VERSION < 33
1770  /* Short circuit and return if we have infinite coordinates */
1771  /* GEOS 3.3+ is supposed to handle this stuff OK */
1772  if ( gserialized_get_gbox_p(geom, &box) )
1773  {
1774  if ( isinf(box.xmax) || isinf(box.ymax) || isinf(box.xmin) || isinf(box.ymin) ||
1775  isnan(box.xmax) || isnan(box.ymax) || isnan(box.xmin) || isnan(box.ymin) )
1776  {
1777  const char *rsn = "Geometry contains an Inf or NaN coordinate";
1778  size_t len = strlen(rsn);
1779  result = palloc(VARHDRSZ + len);
1780  SET_VARSIZE(result, VARHDRSZ + len);
1781  memcpy(VARDATA(result), rsn, len);
1782  PG_FREE_IF_COPY(geom, 0);
1783  PG_RETURN_POINTER(result);
1784  }
1785  }
1786 #endif
1787 
1788  initGEOS(lwnotice, lwgeom_geos_error);
1789 
1790  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom);
1791  if ( g1 )
1792  {
1793  reason_str = GEOSisValidReason(g1);
1794  GEOSGeom_destroy((GEOSGeometry *)g1);
1795  if (reason_str == NULL)
1796  {
1797  elog(ERROR,"GEOSisValidReason() threw an error: %s", lwgeom_geos_errmsg);
1798  PG_RETURN_NULL(); /* never get here */
1799  }
1800  result = cstring2text(reason_str);
1801  GEOSFree(reason_str);
1802  }
1803  else
1804  {
1805  result = cstring2text(lwgeom_geos_errmsg);
1806  }
1807 
1808 
1809  PG_FREE_IF_COPY(geom, 0);
1810  PG_RETURN_POINTER(result);
1811 
1812 }
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
double xmax
Definition: liblwgeom.h:249
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
char ** result
Definition: liblwgeom.h:218
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
double ymin
Definition: liblwgeom.h:250
LWGEOM * geom
double xmin
Definition: liblwgeom.h:248
void lwgeom_geos_error(const char *fmt,...)
double ymax
Definition: liblwgeom.h:251
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)

Here is the call graph for this function: