PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ LWGEOM_ChaikinSmoothing()

Datum LWGEOM_ChaikinSmoothing ( PG_FUNCTION_ARGS  )

Definition at line 130 of file lwgeom_functions_analytic.c.

131{
132 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
133 GSERIALIZED *result;
134 int type = gserialized_get_type(geom);
135 LWGEOM *in;
136 LWGEOM *out;
137 int preserve_endpoints=1;
138 int n_iterations=1;
139
140 if ( type == POINTTYPE || type == MULTIPOINTTYPE )
141 PG_RETURN_POINTER(geom);
142
143 if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
144 n_iterations = PG_GETARG_INT32(1);
145
146 if (n_iterations< 1 || n_iterations>5)
147 elog(ERROR,"Number of iterations must be between 1 and 5 : %s", __func__);
148
149 if ( (PG_NARGS()>2) && (!PG_ARGISNULL(2)) )
150 {
151 if(PG_GETARG_BOOL(2))
152 preserve_endpoints = 1;
153 else
154 preserve_endpoints = 0;
155 }
156
157 in = lwgeom_from_gserialized(geom);
158
159 out = lwgeom_chaikin(in, n_iterations, preserve_endpoints);
160 if ( ! out ) PG_RETURN_NULL();
161
162 /* COMPUTE_BBOX TAINTING */
163 if ( in->bbox ) lwgeom_add_bbox(out);
164
165 result = geometry_serialize(out);
166 lwgeom_free(out);
167 PG_FREE_IF_COPY(geom, 0);
168 PG_RETURN_POINTER(result);
169}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition gserialized.c:89
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1138
#define MULTIPOINTTYPE
Definition liblwgeom.h:119
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition liblwgeom.h:116
LWGEOM * lwgeom_chaikin(const LWGEOM *igeom, int n_iterations, int preserve_endpoint)
Definition lwchaikins.c:182
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition lwgeom.c:677
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
GBOX * bbox
Definition liblwgeom.h:444

References LWGEOM::bbox, geometry_serialize(), gserialized_get_type(), lwgeom_add_bbox(), lwgeom_chaikin(), lwgeom_free(), lwgeom_from_gserialized(), MULTIPOINTTYPE, and POINTTYPE.

Here is the call graph for this function: