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

◆ LWGEOM_segmentize2d()

Datum LWGEOM_segmentize2d ( PG_FUNCTION_ARGS  )

Definition at line 1837 of file lwgeom_functions_basic.c.

1838{
1839 GSERIALIZED *outgeom, *ingeom;
1840 double dist;
1841 LWGEOM *inlwgeom, *outlwgeom;
1842 int type;
1843
1844 POSTGIS_DEBUG(2, "LWGEOM_segmentize2d called");
1845
1846 ingeom = PG_GETARG_GSERIALIZED_P(0);
1847 dist = PG_GETARG_FLOAT8(1);
1848 type = gserialized_get_type(ingeom);
1849
1850 /* Avoid types we cannot segmentize. */
1851 if ((type == POINTTYPE) || (type == MULTIPOINTTYPE) || (type == TRIANGLETYPE) || (type == TINTYPE) ||
1852 (type == POLYHEDRALSURFACETYPE))
1853 {
1854 PG_RETURN_POINTER(ingeom);
1855 }
1856
1857 if (dist <= 0)
1858 {
1859 /* Protect from knowingly infinite loops, see #1799 */
1860 /* Note that we'll end out of memory anyway for other small distances */
1861 elog(ERROR, "ST_Segmentize: invalid max_distance %g (must be >= 0)", dist);
1862 PG_RETURN_NULL();
1863 }
1864
1865 LWGEOM_INIT();
1866
1867 inlwgeom = lwgeom_from_gserialized(ingeom);
1868 if (lwgeom_is_empty(inlwgeom))
1869 {
1870 /* Should only happen on interruption */
1871 lwgeom_free(inlwgeom);
1872 PG_RETURN_POINTER(ingeom);
1873 }
1874
1875 outlwgeom = lwgeom_segmentize2d(inlwgeom, dist);
1876 if (!outlwgeom)
1877 {
1878 /* Should only happen on interruption */
1879 PG_FREE_IF_COPY(ingeom, 0);
1880 PG_RETURN_NULL();
1881 }
1882
1883 /* Copy input bounding box if any */
1884 if (inlwgeom->bbox)
1885 outlwgeom->bbox = gbox_copy(inlwgeom->bbox);
1886
1887 outgeom = geometry_serialize(outlwgeom);
1888
1889 // lwgeom_free(outlwgeom); /* TODO fix lwgeom_clone / ptarray_clone_deep for consistent semantics */
1890 lwgeom_free(inlwgeom);
1891
1892 PG_FREE_IF_COPY(ingeom, 0);
1893
1894 PG_RETURN_POINTER(outgeom);
1895}
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition gbox.c:438
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
#define MULTIPOINTTYPE
Definition liblwgeom.h:105
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition liblwgeom.h:102
#define TINTYPE
Definition liblwgeom.h:116
#define POLYHEDRALSURFACETYPE
Definition liblwgeom.h:114
#define TRIANGLETYPE
Definition liblwgeom.h:115
LWGEOM * lwgeom_segmentize2d(const LWGEOM *line, double dist)
Definition lwgeom.c:799
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:199
GBOX * bbox
Definition liblwgeom.h:458

References LWGEOM::bbox, gbox_copy(), gserialized_get_type(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), lwgeom_segmentize2d(), MULTIPOINTTYPE, POINTTYPE, POLYHEDRALSURFACETYPE, TINTYPE, and TRIANGLETYPE.

Here is the call graph for this function: