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

Definition at line 1778 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.

1779 {
1780  GSERIALIZED *outgeom, *ingeom;
1781  double dist;
1782  LWGEOM *inlwgeom, *outlwgeom;
1783  int type;
1784 
1785  POSTGIS_DEBUG(2, "LWGEOM_segmentize2d called");
1786 
1787  ingeom = PG_GETARG_GSERIALIZED_P(0);
1788  dist = PG_GETARG_FLOAT8(1);
1789  type = gserialized_get_type(ingeom);
1790 
1791  /* Avoid types we cannot segmentize. */
1792  if ( (type == POINTTYPE) ||
1793  (type == MULTIPOINTTYPE) ||
1794  (type == TRIANGLETYPE) ||
1795  (type == TINTYPE) ||
1796  (type == POLYHEDRALSURFACETYPE) )
1797  {
1798  PG_RETURN_POINTER(ingeom);
1799  }
1800 
1801  if ( dist <= 0 ) {
1802  /* Protect from knowingly infinite loops, see #1799 */
1803  /* Note that we'll end out of memory anyway for other small distances */
1804  elog(ERROR, "ST_Segmentize: invalid max_distance %g (must be >= 0)", dist);
1805  PG_RETURN_NULL();
1806  }
1807 
1808  LWGEOM_INIT();
1809 
1810  inlwgeom = lwgeom_from_gserialized(ingeom);
1811  if ( lwgeom_is_empty(inlwgeom) )
1812  {
1813  /* Should only happen on interruption */
1814  lwgeom_free(inlwgeom);
1815  PG_RETURN_POINTER(ingeom);
1816  }
1817 
1818  outlwgeom = lwgeom_segmentize2d(inlwgeom, dist);
1819  if ( ! outlwgeom ) {
1820  /* Should only happen on interruption */
1821  PG_FREE_IF_COPY(ingeom, 0);
1822  PG_RETURN_NULL();
1823  }
1824 
1825  /* Copy input bounding box if any */
1826  if ( inlwgeom->bbox )
1827  outlwgeom->bbox = gbox_copy(inlwgeom->bbox);
1828 
1829  outgeom = geometry_serialize(outlwgeom);
1830 
1831  //lwgeom_free(outlwgeom); /* TODO fix lwgeom_clone / ptarray_clone_deep for consistent semantics */
1832  lwgeom_free(inlwgeom);
1833 
1834  PG_FREE_IF_COPY(ingeom, 0);
1835 
1836  PG_RETURN_POINTER(outgeom);
1837 }
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:403
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:55
GBOX * bbox
Definition: liblwgeom.h:382
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
#define TRIANGLETYPE
Definition: liblwgeom.h:83
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:82
#define TINTYPE
Definition: liblwgeom.h:84
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWGEOM * lwgeom_segmentize2d(LWGEOM *line, double dist)
Definition: lwgeom.c:668
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
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:1297

Here is the call graph for this function: