PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

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

1696 {
1697  GSERIALIZED *geom = NULL;
1698  const GEOSGeometry *g1 = NULL;
1699  char *values[3]; /* valid bool, reason text, location geometry */
1700  char *geos_reason = NULL;
1701  char *reason = NULL;
1702  GEOSGeometry *geos_location = NULL;
1703  LWGEOM *location = NULL;
1704  char valid = 0;
1705  HeapTupleHeader result;
1706  TupleDesc tupdesc;
1707  HeapTuple tuple;
1708  AttInMetadata *attinmeta;
1709  int flags = 0;
1710 
1711  /*
1712  * Build a tuple description for a
1713  * valid_detail tuple
1714  */
1715  get_call_result_type(fcinfo, 0, &tupdesc);
1716  BlessTupleDesc(tupdesc);
1717 
1718  /*
1719  * generate attribute metadata needed later to produce
1720  * tuples from raw C strings
1721  */
1722  attinmeta = TupleDescGetAttInMetadata(tupdesc);
1723 
1724  geom = PG_GETARG_GSERIALIZED_P(0);
1725  flags = PG_GETARG_INT32(1);
1726 
1727  initGEOS(lwpgnotice, lwgeom_geos_error);
1728 
1729  g1 = POSTGIS2GEOS(geom);
1730 
1731  if ( g1 )
1732  {
1733  valid = GEOSisValidDetail(g1, flags, &geos_reason, &geos_location);
1734  GEOSGeom_destroy((GEOSGeometry *)g1);
1735  if ( geos_reason )
1736  {
1737  reason = pstrdup(geos_reason);
1738  GEOSFree(geos_reason);
1739  }
1740  if ( geos_location )
1741  {
1742  location = GEOS2LWGEOM(geos_location, GEOSHasZ(geos_location));
1743  GEOSGeom_destroy(geos_location);
1744  }
1745 
1746  if (valid == 2)
1747  {
1748  /* NOTE: should only happen on OOM or similar */
1749  lwpgerror("GEOS isvaliddetail() threw an exception!");
1750  PG_RETURN_NULL(); /* never gets here */
1751  }
1752  }
1753  else
1754  {
1755  /* TODO: check lwgeom_geos_errmsg for validity error */
1756  reason = pstrdup(lwgeom_geos_errmsg);
1757  }
1758 
1759  /* the boolean validity */
1760  values[0] = valid ? "t" : "f";
1761 
1762  /* the reason */
1763  values[1] = reason;
1764 
1765  /* the location */
1766  values[2] = location ? lwgeom_to_hexwkb_buffer(location, WKB_EXTENDED) : 0;
1767 
1768  tuple = BuildTupleFromCStrings(attinmeta, values);
1769  result = (HeapTupleHeader) palloc(tuple->t_len);
1770  memcpy(result, tuple->t_data, tuple->t_len);
1771  heap_freetuple(tuple);
1772 
1773  PG_RETURN_HEAPTUPLEHEADER(result);
1774 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
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:2148
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: