PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum LWGEOM_segmentize2d ( PG_FUNCTION_ARGS  )

Definition at line 1815 of file lwgeom_functions_basic.c.

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

1816 {
1817  GSERIALIZED *outgeom, *ingeom;
1818  double dist;
1819  LWGEOM *inlwgeom, *outlwgeom;
1820  int type;
1821 
1822  POSTGIS_DEBUG(2, "LWGEOM_segmentize2d called");
1823 
1824  ingeom = PG_GETARG_GSERIALIZED_P(0);
1825  dist = PG_GETARG_FLOAT8(1);
1826  type = gserialized_get_type(ingeom);
1827 
1828  /* Avoid types we cannot segmentize. */
1829  if ( (type == POINTTYPE) ||
1830  (type == MULTIPOINTTYPE) ||
1831  (type == TRIANGLETYPE) ||
1832  (type == TINTYPE) ||
1833  (type == POLYHEDRALSURFACETYPE) )
1834  {
1835  PG_RETURN_POINTER(ingeom);
1836  }
1837 
1838  if ( dist <= 0 ) {
1839  /* Protect from knowingly infinite loops, see #1799 */
1840  /* Note that we'll end out of memory anyway for other small distances */
1841  elog(ERROR, "ST_Segmentize: invalid max_distance %g (must be >= 0)", dist);
1842  PG_RETURN_NULL();
1843  }
1844 
1845  LWGEOM_INIT();
1846 
1847  inlwgeom = lwgeom_from_gserialized(ingeom);
1848  if ( lwgeom_is_empty(inlwgeom) )
1849  {
1850  /* Should only happen on interruption */
1851  lwgeom_free(inlwgeom);
1852  PG_RETURN_POINTER(ingeom);
1853  }
1854 
1855  outlwgeom = lwgeom_segmentize2d(inlwgeom, dist);
1856  if ( ! outlwgeom ) {
1857  /* Should only happen on interruption */
1858  PG_FREE_IF_COPY(ingeom, 0);
1859  PG_RETURN_NULL();
1860  }
1861 
1862  /* Copy input bounding box if any */
1863  if ( inlwgeom->bbox )
1864  outlwgeom->bbox = gbox_copy(inlwgeom->bbox);
1865 
1866  outgeom = geometry_serialize(outlwgeom);
1867 
1868  //lwgeom_free(outlwgeom); /* TODO fix lwgeom_clone / ptarray_clone_deep for consistent semantics */
1869  lwgeom_free(inlwgeom);
1870 
1871  PG_FREE_IF_COPY(ingeom, 0);
1872 
1873  PG_RETURN_POINTER(outgeom);
1874 }
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:433
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Definition: g_serialized.c:86
GBOX * bbox
Definition: liblwgeom.h:397
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
#define TRIANGLETYPE
Definition: liblwgeom.h:97
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:96
LWGEOM * lwgeom_segmentize2d(const LWGEOM *line, double dist)
Definition: lwgeom.c:755
#define TINTYPE
Definition: liblwgeom.h:98
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1386

Here is the call graph for this function: