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

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

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

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

Here is the call graph for this function: