PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

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

1533 {
1534  GSERIALIZED *geom = NULL;
1535  const GEOSGeometry *g1 = NULL;
1536  char *values[3]; /* valid bool, reason text, location geometry */
1537  char *geos_reason = NULL;
1538  char *reason = NULL;
1539  GEOSGeometry *geos_location = NULL;
1540  LWGEOM *location = NULL;
1541  char valid = 0;
1542  HeapTupleHeader result;
1543  TupleDesc tupdesc;
1544  HeapTuple tuple;
1545  AttInMetadata *attinmeta;
1546  int flags = 0;
1547 
1548  /*
1549  * Build a tuple description for a
1550  * valid_detail tuple
1551  */
1552  get_call_result_type(fcinfo, 0, &tupdesc);
1553  BlessTupleDesc(tupdesc);
1554 
1555  /*
1556  * generate attribute metadata needed later to produce
1557  * tuples from raw C strings
1558  */
1559  attinmeta = TupleDescGetAttInMetadata(tupdesc);
1560 
1561  geom = PG_GETARG_GSERIALIZED_P(0);
1562  flags = PG_GETARG_INT32(1);
1563 
1564  initGEOS(lwpgnotice, lwgeom_geos_error);
1565 
1566  g1 = POSTGIS2GEOS(geom);
1567 
1568  if ( g1 )
1569  {
1570  valid = GEOSisValidDetail(g1, flags, &geos_reason, &geos_location);
1571  GEOSGeom_destroy((GEOSGeometry *)g1);
1572  if ( geos_reason )
1573  {
1574  reason = pstrdup(geos_reason);
1575  GEOSFree(geos_reason);
1576  }
1577  if ( geos_location )
1578  {
1579  location = GEOS2LWGEOM(geos_location, GEOSHasZ(geos_location));
1580  GEOSGeom_destroy(geos_location);
1581  }
1582 
1583  if (valid == 2)
1584  {
1585  /* NOTE: should only happen on OOM or similar */
1586  lwpgerror("GEOS isvaliddetail() threw an exception!");
1587  PG_RETURN_NULL(); /* never gets here */
1588  }
1589  }
1590  else
1591  {
1592  /* TODO: check lwgeom_geos_errmsg for validity error */
1593  reason = pstrdup(lwgeom_geos_errmsg);
1594  }
1595 
1596  /* the boolean validity */
1597  values[0] = valid ? "t" : "f";
1598 
1599  /* the reason */
1600  values[1] = reason;
1601 
1602  /* the location */
1603  values[2] = location ? lwgeom_to_hexwkb(location, WKB_EXTENDED, 0) : 0;
1604 
1605  tuple = BuildTupleFromCStrings(attinmeta, values);
1606  result = (HeapTupleHeader) palloc(tuple->t_len);
1607  memcpy(result, tuple->t_data, tuple->t_len);
1608  heap_freetuple(tuple);
1609 
1610  PG_RETURN_HEAPTUPLEHEADER(result);
1611 }
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:2123
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:874
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: