PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

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

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

References GEOS2LWGEOM(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwgeom_to_hexwkb_buffer(), POSTGIS2GEOS(), result, and WKB_EXTENDED.

Here is the call graph for this function: