PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

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

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

References GEOS2LWGEOM(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwgeom_to_hexwkb(), POSTGIS2GEOS(), and WKB_EXTENDED.

Here is the call graph for this function: