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

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

References GEOS2LWGEOM(), lwerror(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwgeom_to_hexwkb(), lwnotice(), POSTGIS2GEOS(), POSTGIS_GEOS_VERSION, result, and WKB_EXTENDED.

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

Here is the call graph for this function: