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

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

1851 {
1852  GSERIALIZED *outgeom, *ingeom;
1853  double dist;
1854  LWGEOM *inlwgeom, *outlwgeom;
1855  int type;
1856 
1857  POSTGIS_DEBUG(2, "LWGEOM_segmentize2d called");
1858 
1859  ingeom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1860  dist = PG_GETARG_FLOAT8(1);
1861  type = gserialized_get_type(ingeom);
1862 
1863  /* Avoid types we cannot segmentize. */
1864  if ( (type == POINTTYPE) ||
1865  (type == MULTIPOINTTYPE) ||
1866  (type == TRIANGLETYPE) ||
1867  (type == TINTYPE) ||
1868  (type == POLYHEDRALSURFACETYPE) )
1869  {
1870  PG_RETURN_POINTER(ingeom);
1871  }
1872 
1873  if ( dist <= 0 ) {
1874  /* Protect from knowingly infinite loops, see #1799 */
1875  /* Note that we'll end out of memory anyway for other small distances */
1876  elog(ERROR, "ST_Segmentize: invalid max_distance %g (must be >= 0)", dist);
1877  PG_RETURN_NULL();
1878  }
1879 
1880  inlwgeom = lwgeom_from_gserialized(ingeom);
1881 
1882  if ( lwgeom_is_empty(inlwgeom) )
1883  {
1884  lwgeom_free(inlwgeom);
1885  PG_RETURN_POINTER(ingeom);
1886  }
1887 
1888  outlwgeom = lwgeom_segmentize2d(inlwgeom, dist);
1889 
1890  /* Copy input bounding box if any */
1891  if ( inlwgeom->bbox )
1892  outlwgeom->bbox = gbox_copy(inlwgeom->bbox);
1893 
1894  outgeom = geometry_serialize(outlwgeom);
1895 
1896  //lwgeom_free(outlwgeom); /* TODO fix lwgeom_clone / ptarray_clone_deep for consistent semantics */
1897  lwgeom_free(inlwgeom);
1898 
1899  PG_FREE_IF_COPY(ingeom, 0);
1900 
1901  PG_RETURN_POINTER(outgeom);
1902 }
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:362
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:56
GBOX * bbox
Definition: liblwgeom.h:354
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
#define MULTIPOINTTYPE
Definition: liblwgeom.h:63
#define TRIANGLETYPE
Definition: liblwgeom.h:73
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:72
#define TINTYPE
Definition: liblwgeom.h:74
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWGEOM * lwgeom_segmentize2d(LWGEOM *line, double dist)
Definition: lwgeom.c:624
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
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:1229

Here is the call graph for this function: