PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ LWGEOM_segmentize2d()

Datum LWGEOM_segmentize2d ( PG_FUNCTION_ARGS  )

Definition at line 1818 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().

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