PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ LWGEOM_segmentize2d()

Datum LWGEOM_segmentize2d ( PG_FUNCTION_ARGS  )

Definition at line 1808 of file lwgeom_functions_basic.c.

1809 {
1810  GSERIALIZED *outgeom, *ingeom;
1811  double dist;
1812  LWGEOM *inlwgeom, *outlwgeom;
1813  int type;
1814 
1815  POSTGIS_DEBUG(2, "LWGEOM_segmentize2d called");
1816 
1817  ingeom = PG_GETARG_GSERIALIZED_P(0);
1818  dist = PG_GETARG_FLOAT8(1);
1819  type = gserialized_get_type(ingeom);
1820 
1821  /* Avoid types we cannot segmentize. */
1822  if ((type == POINTTYPE) || (type == MULTIPOINTTYPE) || (type == TRIANGLETYPE) || (type == TINTYPE) ||
1824  {
1825  PG_RETURN_POINTER(ingeom);
1826  }
1827 
1828  if (dist <= 0)
1829  {
1830  /* Protect from knowingly infinite loops, see #1799 */
1831  /* Note that we'll end out of memory anyway for other small distances */
1832  elog(ERROR, "ST_Segmentize: invalid max_distance %g (must be >= 0)", dist);
1833  PG_RETURN_NULL();
1834  }
1835 
1836  LWGEOM_INIT();
1837 
1838  inlwgeom = lwgeom_from_gserialized(ingeom);
1839  if (lwgeom_is_empty(inlwgeom))
1840  {
1841  /* Should only happen on interruption */
1842  lwgeom_free(inlwgeom);
1843  PG_RETURN_POINTER(ingeom);
1844  }
1845 
1846  outlwgeom = lwgeom_segmentize2d(inlwgeom, dist);
1847  if (!outlwgeom)
1848  {
1849  /* Should only happen on interruption */
1850  PG_FREE_IF_COPY(ingeom, 0);
1851  PG_RETURN_NULL();
1852  }
1853 
1854  /* Copy input bounding box if any */
1855  if (inlwgeom->bbox)
1856  outlwgeom->bbox = gbox_copy(inlwgeom->bbox);
1857 
1858  outgeom = geometry_serialize(outlwgeom);
1859 
1860  // lwgeom_free(outlwgeom); /* TODO fix lwgeom_clone / ptarray_clone_deep for consistent semantics */
1861  lwgeom_free(inlwgeom);
1862 
1863  PG_FREE_IF_COPY(ingeom, 0);
1864 
1865  PG_RETURN_POINTER(outgeom);
1866 }
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: gbox.c:426
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized.c:89
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
LWGEOM * lwgeom_segmentize2d(const LWGEOM *line, double dist)
Definition: lwgeom.c:753
#define MULTIPOINTTYPE
Definition: liblwgeom.h:119
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:116
#define TINTYPE
Definition: liblwgeom.h:130
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:128
#define TRIANGLETYPE
Definition: liblwgeom.h:129
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:193
type
Definition: ovdump.py:42
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
GBOX * bbox
Definition: liblwgeom.h:444

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

Here is the call graph for this function: