PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ isvaliddetail()

Datum isvaliddetail ( PG_FUNCTION_ARGS  )

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

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