PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

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

1655 {
1656  GSERIALIZED *geom = NULL;
1657  const GEOSGeometry *g1 = NULL;
1658  char *values[3]; /* valid bool, reason text, location geometry */
1659  char *geos_reason = NULL;
1660  char *reason = NULL;
1661  GEOSGeometry *geos_location = NULL;
1662  LWGEOM *location = NULL;
1663  char valid = 0;
1664  HeapTupleHeader result;
1665  TupleDesc tupdesc;
1666  HeapTuple tuple;
1667  AttInMetadata *attinmeta;
1668  int flags = 0;
1669 
1670  /*
1671  * Build a tuple description for a
1672  * valid_detail tuple
1673  */
1674  get_call_result_type(fcinfo, 0, &tupdesc);
1675  BlessTupleDesc(tupdesc);
1676 
1677  /*
1678  * generate attribute metadata needed later to produce
1679  * tuples from raw C strings
1680  */
1681  attinmeta = TupleDescGetAttInMetadata(tupdesc);
1682 
1683  geom = PG_GETARG_GSERIALIZED_P(0);
1684  flags = PG_GETARG_INT32(1);
1685 
1686  initGEOS(lwpgnotice, lwgeom_geos_error);
1687 
1688  g1 = POSTGIS2GEOS(geom);
1689 
1690  if ( g1 )
1691  {
1692  valid = GEOSisValidDetail(g1, flags, &geos_reason, &geos_location);
1693  GEOSGeom_destroy((GEOSGeometry *)g1);
1694  if ( geos_reason )
1695  {
1696  reason = pstrdup(geos_reason);
1697  GEOSFree(geos_reason);
1698  }
1699  if ( geos_location )
1700  {
1701  location = GEOS2LWGEOM(geos_location, GEOSHasZ(geos_location));
1702  GEOSGeom_destroy(geos_location);
1703  }
1704 
1705  if (valid == 2)
1706  {
1707  /* NOTE: should only happen on OOM or similar */
1708  lwpgerror("GEOS isvaliddetail() threw an exception!");
1709  PG_RETURN_NULL(); /* never gets here */
1710  }
1711  }
1712  else
1713  {
1714  /* TODO: check lwgeom_geos_errmsg for validity error */
1715  reason = pstrdup(lwgeom_geos_errmsg);
1716  }
1717 
1718  /* the boolean validity */
1719  values[0] = valid ? "t" : "f";
1720 
1721  /* the reason */
1722  values[1] = reason;
1723 
1724  /* the location */
1725  values[2] = location ? lwgeom_to_hexwkb_buffer(location, WKB_EXTENDED) : 0;
1726 
1727  tuple = BuildTupleFromCStrings(attinmeta, values);
1728  result = (HeapTupleHeader) palloc(tuple->t_len);
1729  memcpy(result, tuple->t_data, tuple->t_len);
1730  heap_freetuple(tuple);
1731 
1732  PG_RETURN_HEAPTUPLEHEADER(result);
1733 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
void lwgeom_geos_error(const char *fmt,...)
void(*) LWGEOM GEOS2LWGEOM)(const GEOSGeometry *geom, uint8_t want3d)
char * lwgeom_to_hexwkb_buffer(const LWGEOM *geom, uint8_t variant)
Definition: lwout_wkb.c:845
#define WKB_EXTENDED
Definition: liblwgeom.h:2209
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)

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

Here is the call graph for this function: