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

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

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

1573 {
1574  GSERIALIZED *geom = NULL;
1575  const GEOSGeometry *g1 = NULL;
1576  char *values[3]; /* valid bool, reason text, location geometry */
1577  char *geos_reason = NULL;
1578  char *reason = NULL;
1579  GEOSGeometry *geos_location = NULL;
1580  LWGEOM *location = NULL;
1581  char valid = 0;
1582  HeapTupleHeader result;
1583  TupleDesc tupdesc;
1584  HeapTuple tuple;
1585  AttInMetadata *attinmeta;
1586  int flags = 0;
1587 
1588  /*
1589  * Build a tuple description for a
1590  * valid_detail tuple
1591  */
1592  tupdesc = RelationNameGetTupleDesc("valid_detail");
1593  if ( ! tupdesc )
1594  {
1595  lwpgerror("TYPE valid_detail not found");
1596  PG_RETURN_NULL();
1597  }
1598 
1599  /*
1600  * generate attribute metadata needed later to produce
1601  * tuples from raw C strings
1602  */
1603  attinmeta = TupleDescGetAttInMetadata(tupdesc);
1604 
1605  geom = PG_GETARG_GSERIALIZED_P(0);
1606 
1607  if ( PG_NARGS() > 1 && ! PG_ARGISNULL(1) )
1608  {
1609  flags = PG_GETARG_INT32(1);
1610  }
1611 
1612  initGEOS(lwpgnotice, lwgeom_geos_error);
1613 
1614  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom);
1615 
1616  if ( g1 )
1617  {
1618  valid = GEOSisValidDetail(g1, flags,
1619  &geos_reason, &geos_location);
1620  GEOSGeom_destroy((GEOSGeometry *)g1);
1621  if ( geos_reason )
1622  {
1623  reason = pstrdup(geos_reason);
1624  GEOSFree(geos_reason);
1625  }
1626  if ( geos_location )
1627  {
1628  location = GEOS2LWGEOM(geos_location, GEOSHasZ(geos_location));
1629  GEOSGeom_destroy((GEOSGeometry *)geos_location);
1630  }
1631 
1632  if (valid == 2)
1633  {
1634  /* NOTE: should only happen on OOM or similar */
1635  lwpgerror("GEOS isvaliddetail() threw an exception!");
1636  PG_RETURN_NULL(); /* never gets here */
1637  }
1638  }
1639  else
1640  {
1641  /* TODO: check lwgeom_geos_errmsg for validity error */
1642  reason = pstrdup(lwgeom_geos_errmsg);
1643  }
1644 
1645  /* the boolean validity */
1646  values[0] = valid ? "t" : "f";
1647 
1648  /* the reason */
1649  values[1] = reason;
1650 
1651  /* the location */
1652  values[2] = location ? lwgeom_to_hexwkb(location, WKB_EXTENDED, 0) : 0;
1653 
1654  tuple = BuildTupleFromCStrings(attinmeta, values);
1655  result = (HeapTupleHeader) palloc(tuple->t_len);
1656  memcpy(result, tuple->t_data, tuple->t_len);
1657  heap_freetuple(tuple);
1658 
1659  PG_RETURN_HEAPTUPLEHEADER(result);
1660 }
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:2061
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)

Here is the call graph for this function: