PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

Definition at line 1820 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(), POSTGIS_GEOS_VERSION, and WKB_EXTENDED.

Referenced by isvalidreason().

1821 {
1822 #if POSTGIS_GEOS_VERSION < 33
1823  lwpgerror("The GEOS version this PostGIS binary "
1824  "was compiled against (%d) doesn't support "
1825  "'isValidDetail' function (3.3.0+ required)",
1827  PG_RETURN_NULL();
1828 #else /* POSTGIS_GEOS_VERSION >= 33 */
1829 
1830  GSERIALIZED *geom = NULL;
1831  const GEOSGeometry *g1 = NULL;
1832  char *values[3]; /* valid bool, reason text, location geometry */
1833  char *geos_reason = NULL;
1834  char *reason = NULL;
1835  GEOSGeometry *geos_location = NULL;
1836  LWGEOM *location = NULL;
1837  char valid = 0;
1838  HeapTupleHeader result;
1839  TupleDesc tupdesc;
1840  HeapTuple tuple;
1841  AttInMetadata *attinmeta;
1842  int flags = 0;
1843 
1844  /*
1845  * Build a tuple description for a
1846  * valid_detail tuple
1847  */
1848  tupdesc = RelationNameGetTupleDesc("valid_detail");
1849  if ( ! tupdesc )
1850  {
1851  lwpgerror("TYPE valid_detail not found");
1852  PG_RETURN_NULL();
1853  }
1854 
1855  /*
1856  * generate attribute metadata needed later to produce
1857  * tuples from raw C strings
1858  */
1859  attinmeta = TupleDescGetAttInMetadata(tupdesc);
1860 
1861  geom = PG_GETARG_GSERIALIZED_P(0);
1862 
1863  if ( PG_NARGS() > 1 && ! PG_ARGISNULL(1) )
1864  {
1865  flags = PG_GETARG_INT32(1);
1866  }
1867 
1868  initGEOS(lwpgnotice, lwgeom_geos_error);
1869 
1870  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom);
1871 
1872  if ( g1 )
1873  {
1874  valid = GEOSisValidDetail(g1, flags,
1875  &geos_reason, &geos_location);
1876  GEOSGeom_destroy((GEOSGeometry *)g1);
1877  if ( geos_reason )
1878  {
1879  reason = pstrdup(geos_reason);
1880  GEOSFree(geos_reason);
1881  }
1882  if ( geos_location )
1883  {
1884  location = GEOS2LWGEOM(geos_location, GEOSHasZ(geos_location));
1885  GEOSGeom_destroy((GEOSGeometry *)geos_location);
1886  }
1887 
1888  if (valid == 2)
1889  {
1890  /* NOTE: should only happen on OOM or similar */
1891  lwpgerror("GEOS isvaliddetail() threw an exception!");
1892  PG_RETURN_NULL(); /* never gets here */
1893  }
1894  }
1895  else
1896  {
1897  /* TODO: check lwgeom_geos_errmsg for validity error */
1898  reason = pstrdup(lwgeom_geos_errmsg);
1899  }
1900 
1901  /* the boolean validity */
1902  values[0] = valid ? "t" : "f";
1903 
1904  /* the reason */
1905  values[1] = reason;
1906 
1907  /* the location */
1908  values[2] = location ? lwgeom_to_hexwkb(location, WKB_EXTENDED, 0) : 0;
1909 
1910  tuple = BuildTupleFromCStrings(attinmeta, values);
1911  result = (HeapTupleHeader) palloc(tuple->t_len);
1912  memcpy(result, tuple->t_data, tuple->t_len);
1913  heap_freetuple(tuple);
1914 
1915  PG_RETURN_HEAPTUPLEHEADER(result);
1916 
1917 #endif /* POSTGIS_GEOS_VERSION >= 33 */
1918 }
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:834
#define POSTGIS_GEOS_VERSION
Definition: sqldefines.h:10
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
LWGEOM * geom
void lwgeom_geos_error(const char *fmt,...)
#define WKB_EXTENDED
Definition: liblwgeom.h:1932
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: