PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

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

1600 {
1601  GSERIALIZED *geom = NULL;
1602  const GEOSGeometry *g1 = NULL;
1603  char *values[3]; /* valid bool, reason text, location geometry */
1604  char *geos_reason = NULL;
1605  char *reason = NULL;
1606  GEOSGeometry *geos_location = NULL;
1607  LWGEOM *location = NULL;
1608  char valid = 0;
1609  HeapTupleHeader result;
1610  TupleDesc tupdesc;
1611  HeapTuple tuple;
1612  AttInMetadata *attinmeta;
1613  int flags = 0;
1614 
1615  /*
1616  * Build a tuple description for a
1617  * valid_detail tuple
1618  */
1619  get_call_result_type(fcinfo, 0, &tupdesc);
1620  BlessTupleDesc(tupdesc);
1621 
1622  /*
1623  * generate attribute metadata needed later to produce
1624  * tuples from raw C strings
1625  */
1626  attinmeta = TupleDescGetAttInMetadata(tupdesc);
1627 
1628  geom = PG_GETARG_GSERIALIZED_P(0);
1629  flags = PG_GETARG_INT32(1);
1630 
1631  initGEOS(lwpgnotice, lwgeom_geos_error);
1632 
1633  g1 = POSTGIS2GEOS(geom);
1634 
1635  if ( g1 )
1636  {
1637  valid = GEOSisValidDetail(g1, flags, &geos_reason, &geos_location);
1638  GEOSGeom_destroy((GEOSGeometry *)g1);
1639  if ( geos_reason )
1640  {
1641  reason = pstrdup(geos_reason);
1642  GEOSFree(geos_reason);
1643  }
1644  if ( geos_location )
1645  {
1646  location = GEOS2LWGEOM(geos_location, GEOSHasZ(geos_location));
1647  GEOSGeom_destroy(geos_location);
1648  }
1649 
1650  if (valid == 2)
1651  {
1652  /* NOTE: should only happen on OOM or similar */
1653  lwpgerror("GEOS isvaliddetail() threw an exception!");
1654  PG_RETURN_NULL(); /* never gets here */
1655  }
1656  }
1657  else
1658  {
1659  /* TODO: check lwgeom_geos_errmsg for validity error */
1660  reason = pstrdup(lwgeom_geos_errmsg);
1661  }
1662 
1663  /* the boolean validity */
1664  values[0] = valid ? "t" : "f";
1665 
1666  /* the reason */
1667  values[1] = reason;
1668 
1669  /* the location */
1670  values[2] = location ? lwgeom_to_hexwkb_buffer(location, WKB_EXTENDED) : 0;
1671 
1672  tuple = BuildTupleFromCStrings(attinmeta, values);
1673  result = (HeapTupleHeader) palloc(tuple->t_len);
1674  memcpy(result, tuple->t_data, tuple->t_len);
1675  heap_freetuple(tuple);
1676 
1677  PG_RETURN_HEAPTUPLEHEADER(result);
1678 }
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:2159
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: