PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_segmentize2d()

Datum LWGEOM_segmentize2d ( PG_FUNCTION_ARGS  )

Definition at line 1811 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_reverse(), lwgeom_segmentize2d(), MULTIPOINTTYPE, PG_FUNCTION_INFO_V1(), POINTTYPE, POLYHEDRALSURFACETYPE, TINTYPE, TRIANGLETYPE, and ovdump::type.

Referenced by LWGEOM_isempty().

1812 {
1813  GSERIALIZED *outgeom, *ingeom;
1814  double dist;
1815  LWGEOM *inlwgeom, *outlwgeom;
1816  int type;
1817 
1818  POSTGIS_DEBUG(2, "LWGEOM_segmentize2d called");
1819 
1820  ingeom = PG_GETARG_GSERIALIZED_P(0);
1821  dist = PG_GETARG_FLOAT8(1);
1822  type = gserialized_get_type(ingeom);
1823 
1824  /* Avoid types we cannot segmentize. */
1825  if ( (type == POINTTYPE) ||
1826  (type == MULTIPOINTTYPE) ||
1827  (type == TRIANGLETYPE) ||
1828  (type == TINTYPE) ||
1829  (type == POLYHEDRALSURFACETYPE) )
1830  {
1831  PG_RETURN_POINTER(ingeom);
1832  }
1833 
1834  if ( dist <= 0 ) {
1835  /* Protect from knowingly infinite loops, see #1799 */
1836  /* Note that we'll end out of memory anyway for other small distances */
1837  elog(ERROR, "ST_Segmentize: invalid max_distance %g (must be >= 0)", dist);
1838  PG_RETURN_NULL();
1839  }
1840 
1841  LWGEOM_INIT();
1842 
1843  inlwgeom = lwgeom_from_gserialized(ingeom);
1844  if ( lwgeom_is_empty(inlwgeom) )
1845  {
1846  /* Should only happen on interruption */
1847  lwgeom_free(inlwgeom);
1848  PG_RETURN_POINTER(ingeom);
1849  }
1850 
1851  outlwgeom = lwgeom_segmentize2d(inlwgeom, dist);
1852  if ( ! outlwgeom ) {
1853  /* Should only happen on interruption */
1854  PG_FREE_IF_COPY(ingeom, 0);
1855  PG_RETURN_NULL();
1856  }
1857 
1858  /* Copy input bounding box if any */
1859  if ( inlwgeom->bbox )
1860  outlwgeom->bbox = gbox_copy(inlwgeom->bbox);
1861 
1862  outgeom = geometry_serialize(outlwgeom);
1863 
1864  //lwgeom_free(outlwgeom); /* TODO fix lwgeom_clone / ptarray_clone_deep for consistent semantics */
1865  lwgeom_free(inlwgeom);
1866 
1867  PG_FREE_IF_COPY(ingeom, 0);
1868 
1869  PG_RETURN_POINTER(outgeom);
1870 }
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:438
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:398
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#define TRIANGLETYPE
Definition: liblwgeom.h:98
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:97
#define TINTYPE
Definition: liblwgeom.h:99
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWGEOM * lwgeom_segmentize2d(LWGEOM *line, double dist)
Definition: lwgeom.c:717
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
type
Definition: ovdump.py:41
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:1346
Here is the call graph for this function:
Here is the caller graph for this function: