PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

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

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