PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

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

References dumpnode::geom, GEOS2LWGEOM(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwgeom_to_hexwkb(), overlaps(), PG_FUNCTION_INFO_V1(), POSTGIS2GEOS(), and WKB_EXTENDED.

Referenced by isvalidreason().

1470 {
1471  GSERIALIZED *geom = NULL;
1472  const GEOSGeometry *g1 = NULL;
1473  char *values[3]; /* valid bool, reason text, location geometry */
1474  char *geos_reason = NULL;
1475  char *reason = NULL;
1476  GEOSGeometry *geos_location = NULL;
1477  LWGEOM *location = NULL;
1478  char valid = 0;
1479  HeapTupleHeader result;
1480  TupleDesc tupdesc;
1481  HeapTuple tuple;
1482  AttInMetadata *attinmeta;
1483  int flags = 0;
1484 
1485  /*
1486  * Build a tuple description for a
1487  * valid_detail tuple
1488  */
1489  tupdesc = RelationNameGetTupleDesc("valid_detail");
1490  if ( ! tupdesc )
1491  {
1492  lwpgerror("TYPE valid_detail not found");
1493  PG_RETURN_NULL();
1494  }
1495 
1496  /*
1497  * generate attribute metadata needed later to produce
1498  * tuples from raw C strings
1499  */
1500  attinmeta = TupleDescGetAttInMetadata(tupdesc);
1501 
1502  geom = PG_GETARG_GSERIALIZED_P(0);
1503 
1504  if ( PG_NARGS() > 1 && ! PG_ARGISNULL(1) )
1505  {
1506  flags = PG_GETARG_INT32(1);
1507  }
1508 
1509  initGEOS(lwpgnotice, lwgeom_geos_error);
1510 
1511  g1 = POSTGIS2GEOS(geom);
1512 
1513  if ( g1 )
1514  {
1515  valid = GEOSisValidDetail(g1, flags, &geos_reason, &geos_location);
1516  GEOSGeom_destroy((GEOSGeometry *)g1);
1517  if ( geos_reason )
1518  {
1519  reason = pstrdup(geos_reason);
1520  GEOSFree(geos_reason);
1521  }
1522  if ( geos_location )
1523  {
1524  location = GEOS2LWGEOM(geos_location, GEOSHasZ(geos_location));
1525  GEOSGeom_destroy(geos_location);
1526  }
1527 
1528  if (valid == 2)
1529  {
1530  /* NOTE: should only happen on OOM or similar */
1531  lwpgerror("GEOS isvaliddetail() threw an exception!");
1532  PG_RETURN_NULL(); /* never gets here */
1533  }
1534  }
1535  else
1536  {
1537  /* TODO: check lwgeom_geos_errmsg for validity error */
1538  reason = pstrdup(lwgeom_geos_errmsg);
1539  }
1540 
1541  /* the boolean validity */
1542  values[0] = valid ? "t" : "f";
1543 
1544  /* the reason */
1545  values[1] = reason;
1546 
1547  /* the location */
1548  values[2] = location ? lwgeom_to_hexwkb(location, WKB_EXTENDED, 0) : 0;
1549 
1550  tuple = BuildTupleFromCStrings(attinmeta, values);
1551  result = (HeapTupleHeader) palloc(tuple->t_len);
1552  memcpy(result, tuple->t_data, tuple->t_len);
1553  heap_freetuple(tuple);
1554 
1555  PG_RETURN_HEAPTUPLEHEADER(result);
1556 }
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:848
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, uint8_t want3d)
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
LWGEOM * geom
void lwgeom_geos_error(const char *fmt,...)
#define WKB_EXTENDED
Definition: liblwgeom.h:2029
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
Here is the call graph for this function:
Here is the caller graph for this function: