PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

Definition at line 1470 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().

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