PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

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

1627 {
1628  GSERIALIZED *geom = NULL;
1629  const GEOSGeometry *g1 = NULL;
1630  char *values[3]; /* valid bool, reason text, location geometry */
1631  char *geos_reason = NULL;
1632  char *reason = NULL;
1633  GEOSGeometry *geos_location = NULL;
1634  LWGEOM *location = NULL;
1635  char valid = 0;
1636  HeapTupleHeader result;
1637  TupleDesc tupdesc;
1638  HeapTuple tuple;
1639  AttInMetadata *attinmeta;
1640  int flags = 0;
1641 
1642  /*
1643  * Build a tuple description for a
1644  * valid_detail tuple
1645  */
1646  get_call_result_type(fcinfo, 0, &tupdesc);
1647  BlessTupleDesc(tupdesc);
1648 
1649  /*
1650  * generate attribute metadata needed later to produce
1651  * tuples from raw C strings
1652  */
1653  attinmeta = TupleDescGetAttInMetadata(tupdesc);
1654 
1655  geom = PG_GETARG_GSERIALIZED_P(0);
1656  flags = PG_GETARG_INT32(1);
1657 
1658  initGEOS(lwpgnotice, lwgeom_geos_error);
1659 
1660  g1 = POSTGIS2GEOS(geom);
1661 
1662  if ( g1 )
1663  {
1664  valid = GEOSisValidDetail(g1, flags, &geos_reason, &geos_location);
1665  GEOSGeom_destroy((GEOSGeometry *)g1);
1666  if ( geos_reason )
1667  {
1668  reason = pstrdup(geos_reason);
1669  GEOSFree(geos_reason);
1670  }
1671  if ( geos_location )
1672  {
1673  location = GEOS2LWGEOM(geos_location, GEOSHasZ(geos_location));
1674  GEOSGeom_destroy(geos_location);
1675  }
1676 
1677  if (valid == 2)
1678  {
1679  /* NOTE: should only happen on OOM or similar */
1680  lwpgerror("GEOS isvaliddetail() threw an exception!");
1681  PG_RETURN_NULL(); /* never gets here */
1682  }
1683  }
1684  else
1685  {
1686  /* TODO: check lwgeom_geos_errmsg for validity error */
1687  reason = pstrdup(lwgeom_geos_errmsg);
1688  }
1689 
1690  /* the boolean validity */
1691  values[0] = valid ? "t" : "f";
1692 
1693  /* the reason */
1694  values[1] = reason;
1695 
1696  /* the location */
1697  values[2] = location ? lwgeom_to_hexwkb_buffer(location, WKB_EXTENDED) : 0;
1698 
1699  tuple = BuildTupleFromCStrings(attinmeta, values);
1700  result = (HeapTupleHeader) palloc(tuple->t_len);
1701  memcpy(result, tuple->t_data, tuple->t_len);
1702  heap_freetuple(tuple);
1703 
1704  PG_RETURN_HEAPTUPLEHEADER(result);
1705 }
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:2158
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: