PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

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

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