PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

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

1630 {
1631  GSERIALIZED *geom = NULL;
1632  const GEOSGeometry *g1 = NULL;
1633  char *values[3]; /* valid bool, reason text, location geometry */
1634  char *geos_reason = NULL;
1635  char *reason = NULL;
1636  GEOSGeometry *geos_location = NULL;
1637  LWGEOM *location = NULL;
1638  char valid = 0;
1639  HeapTupleHeader result;
1640  TupleDesc tupdesc;
1641  HeapTuple tuple;
1642  AttInMetadata *attinmeta;
1643  int flags = 0;
1644 
1645  /*
1646  * Build a tuple description for a
1647  * valid_detail tuple
1648  */
1649  get_call_result_type(fcinfo, 0, &tupdesc);
1650  BlessTupleDesc(tupdesc);
1651 
1652  /*
1653  * generate attribute metadata needed later to produce
1654  * tuples from raw C strings
1655  */
1656  attinmeta = TupleDescGetAttInMetadata(tupdesc);
1657 
1658  geom = PG_GETARG_GSERIALIZED_P(0);
1659 
1660  if ( PG_NARGS() > 1 && ! PG_ARGISNULL(1) )
1661  {
1662  flags = PG_GETARG_INT32(1);
1663  }
1664 
1665  initGEOS(lwpgnotice, lwgeom_geos_error);
1666 
1667  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom);
1668 
1669  if ( g1 )
1670  {
1671  valid = GEOSisValidDetail(g1, flags,
1672  &geos_reason, &geos_location);
1673  GEOSGeom_destroy((GEOSGeometry *)g1);
1674  if ( geos_reason )
1675  {
1676  reason = pstrdup(geos_reason);
1677  GEOSFree(geos_reason);
1678  }
1679  if ( geos_location )
1680  {
1681  location = GEOS2LWGEOM(geos_location, GEOSHasZ(geos_location));
1682  GEOSGeom_destroy((GEOSGeometry *)geos_location);
1683  }
1684 
1685  if (valid == 2)
1686  {
1687  /* NOTE: should only happen on OOM or similar */
1688  lwpgerror("GEOS isvaliddetail() threw an exception!");
1689  PG_RETURN_NULL(); /* never gets here */
1690  }
1691  }
1692  else
1693  {
1694  /* TODO: check lwgeom_geos_errmsg for validity error */
1695  reason = pstrdup(lwgeom_geos_errmsg);
1696  }
1697 
1698  /* the boolean validity */
1699  values[0] = valid ? "t" : "f";
1700 
1701  /* the reason */
1702  values[1] = reason;
1703 
1704  /* the location */
1705  values[2] = location ? lwgeom_to_hexwkb(location, WKB_EXTENDED, 0) : 0;
1706 
1707  tuple = BuildTupleFromCStrings(attinmeta, values);
1708  result = (HeapTupleHeader) palloc(tuple->t_len);
1709  memcpy(result, tuple->t_data, tuple->t_len);
1710  heap_freetuple(tuple);
1711 
1712  PG_RETURN_HEAPTUPLEHEADER(result);
1713 }
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:2076
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)
Here is the call graph for this function:
Here is the caller graph for this function: