PostGIS  2.3.7dev-r@@SVN_REVISION@@
Datum isvaliddetail ( PG_FUNCTION_ARGS  )

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

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

1555 {
1556  GSERIALIZED *geom = NULL;
1557  const GEOSGeometry *g1 = NULL;
1558  char *values[3]; /* valid bool, reason text, location geometry */
1559  char *geos_reason = NULL;
1560  char *reason = NULL;
1561  GEOSGeometry *geos_location = NULL;
1562  LWGEOM *location = NULL;
1563  char valid = 0;
1564  HeapTupleHeader result;
1565  TupleDesc tupdesc;
1566  HeapTuple tuple;
1567  AttInMetadata *attinmeta;
1568  int flags = 0;
1569 
1570  /*
1571  * Build a tuple description for a
1572  * valid_detail tuple
1573  */
1574  tupdesc = RelationNameGetTupleDesc("valid_detail");
1575  if ( ! tupdesc )
1576  {
1577  lwpgerror("TYPE valid_detail not found");
1578  PG_RETURN_NULL();
1579  }
1580 
1581  /*
1582  * generate attribute metadata needed later to produce
1583  * tuples from raw C strings
1584  */
1585  attinmeta = TupleDescGetAttInMetadata(tupdesc);
1586 
1587  geom = PG_GETARG_GSERIALIZED_P(0);
1588 
1589  if ( PG_NARGS() > 1 && ! PG_ARGISNULL(1) )
1590  {
1591  flags = PG_GETARG_INT32(1);
1592  }
1593 
1594  initGEOS(lwpgnotice, lwgeom_geos_error);
1595 
1596  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom);
1597 
1598  if ( g1 )
1599  {
1600  valid = GEOSisValidDetail(g1, flags,
1601  &geos_reason, &geos_location);
1602  GEOSGeom_destroy((GEOSGeometry *)g1);
1603  if ( geos_reason )
1604  {
1605  reason = pstrdup(geos_reason);
1606  GEOSFree(geos_reason);
1607  }
1608  if ( geos_location )
1609  {
1610  location = GEOS2LWGEOM(geos_location, GEOSHasZ(geos_location));
1611  GEOSGeom_destroy((GEOSGeometry *)geos_location);
1612  }
1613 
1614  if (valid == 2)
1615  {
1616  /* NOTE: should only happen on OOM or similar */
1617  lwpgerror("GEOS isvaliddetail() threw an exception!");
1618  PG_RETURN_NULL(); /* never gets here */
1619  }
1620  }
1621  else
1622  {
1623  /* TODO: check lwgeom_geos_errmsg for validity error */
1624  reason = pstrdup(lwgeom_geos_errmsg);
1625  }
1626 
1627  /* the boolean validity */
1628  values[0] = valid ? "t" : "f";
1629 
1630  /* the reason */
1631  values[1] = reason;
1632 
1633  /* the location */
1634  values[2] = location ? lwgeom_to_hexwkb(location, WKB_EXTENDED, 0) : 0;
1635 
1636  tuple = BuildTupleFromCStrings(attinmeta, values);
1637  result = (HeapTupleHeader) palloc(tuple->t_len);
1638  memcpy(result, tuple->t_data, tuple->t_len);
1639  heap_freetuple(tuple);
1640 
1641  PG_RETURN_HEAPTUPLEHEADER(result);
1642 }
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:848
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
LWGEOM * geom
void lwgeom_geos_error(const char *fmt,...)
#define WKB_EXTENDED
Definition: liblwgeom.h:2048
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)

Here is the call graph for this function: