PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

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

1717 {
1718  GSERIALIZED *geom = NULL;
1719  const GEOSGeometry *g1 = NULL;
1720  char *values[3]; /* valid bool, reason text, location geometry */
1721  char *geos_reason = NULL;
1722  char *reason = NULL;
1723  GEOSGeometry *geos_location = NULL;
1724  LWGEOM *location = NULL;
1725  char valid = 0;
1726  HeapTupleHeader result;
1727  TupleDesc tupdesc;
1728  HeapTuple tuple;
1729  AttInMetadata *attinmeta;
1730  int flags = 0;
1731 
1732  /*
1733  * Build a tuple description for a
1734  * valid_detail tuple
1735  */
1736  get_call_result_type(fcinfo, 0, &tupdesc);
1737  BlessTupleDesc(tupdesc);
1738 
1739  /*
1740  * generate attribute metadata needed later to produce
1741  * tuples from raw C strings
1742  */
1743  attinmeta = TupleDescGetAttInMetadata(tupdesc);
1744 
1745  geom = PG_GETARG_GSERIALIZED_P(0);
1746  flags = PG_GETARG_INT32(1);
1747 
1748  initGEOS(lwpgnotice, lwgeom_geos_error);
1749 
1750  g1 = POSTGIS2GEOS(geom);
1751 
1752  if ( g1 )
1753  {
1754  valid = GEOSisValidDetail(g1, flags, &geos_reason, &geos_location);
1755  GEOSGeom_destroy((GEOSGeometry *)g1);
1756  if ( geos_reason )
1757  {
1758  reason = pstrdup(geos_reason);
1759  GEOSFree(geos_reason);
1760  }
1761  if ( geos_location )
1762  {
1763  location = GEOS2LWGEOM(geos_location, GEOSHasZ(geos_location));
1764  GEOSGeom_destroy(geos_location);
1765  }
1766 
1767  if (valid == 2)
1768  {
1769  /* NOTE: should only happen on OOM or similar */
1770  lwpgerror("GEOS isvaliddetail() threw an exception!");
1771  PG_RETURN_NULL(); /* never gets here */
1772  }
1773  }
1774  else
1775  {
1776  /* TODO: check lwgeom_geos_errmsg for validity error */
1777  reason = pstrdup(lwgeom_geos_errmsg);
1778  }
1779 
1780  /* the boolean validity */
1781  values[0] = valid ? "t" : "f";
1782 
1783  /* the reason */
1784  values[1] = reason;
1785 
1786  /* the location */
1787  values[2] = location ? lwgeom_to_hexwkb_buffer(location, WKB_EXTENDED) : 0;
1788 
1789  tuple = BuildTupleFromCStrings(attinmeta, values);
1790  result = (HeapTupleHeader) palloc(tuple->t_len);
1791  memcpy(result, tuple->t_data, tuple->t_len);
1792  heap_freetuple(tuple);
1793 
1794  PG_RETURN_HEAPTUPLEHEADER(result);
1795 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, uint8_t want3d)
void lwgeom_geos_error(const char *fmt,...)
char * lwgeom_to_hexwkb_buffer(const LWGEOM *geom, uint8_t variant)
Definition: lwout_wkb.c:845
#define WKB_EXTENDED
Definition: liblwgeom.h:2177
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)

References GEOS2LWGEOM(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwgeom_to_hexwkb_buffer(), POSTGIS2GEOS(), result, and WKB_EXTENDED.

Here is the call graph for this function: