PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

Definition at line 3301 of file postgis/lwgeom_geos.c.

3302 {
3303  GSERIALIZED* input;
3304  GSERIALIZED* clip;
3305  GSERIALIZED* result;
3306  LWGEOM* lwgeom_input;
3307  LWGEOM* lwgeom_result;
3308  double tolerance;
3309  GBOX clip_envelope;
3310  int custom_clip_envelope;
3311  int return_polygons;
3312 
3313  /* Return NULL on NULL geometry */
3314  if (PG_ARGISNULL(0))
3315  PG_RETURN_NULL();
3316 
3317  /* Read our tolerance value */
3318  if (PG_ARGISNULL(2))
3319  {
3320  lwpgerror("Tolerance must be a positive number.");
3321  PG_RETURN_NULL();
3322  }
3323 
3324  tolerance = PG_GETARG_FLOAT8(2);
3325 
3326  if (tolerance < 0)
3327  {
3328  lwpgerror("Tolerance must be a positive number.");
3329  PG_RETURN_NULL();
3330  }
3331 
3332  /* Are we returning lines or polygons? */
3333  if (PG_ARGISNULL(3))
3334  {
3335  lwpgerror("return_polygons must be true or false.");
3336  PG_RETURN_NULL();
3337  }
3338  return_polygons = PG_GETARG_BOOL(3);
3339 
3340  /* Read our clipping envelope, if applicable. */
3341  custom_clip_envelope = !PG_ARGISNULL(1);
3342  if (custom_clip_envelope) {
3343  clip = PG_GETARG_GSERIALIZED_P(1);
3344  if (!gserialized_get_gbox_p(clip, &clip_envelope))
3345  {
3346  lwpgerror("Could not determine envelope of clipping geometry.");
3347  PG_FREE_IF_COPY(clip, 1);
3348  PG_RETURN_NULL();
3349  }
3350  PG_FREE_IF_COPY(clip, 1);
3351  }
3352 
3353  /* Read our input geometry */
3354  input = PG_GETARG_GSERIALIZED_P(0);
3355 
3356  lwgeom_input = lwgeom_from_gserialized(input);
3357 
3358  if(!lwgeom_input)
3359  {
3360  lwpgerror("Could not read input geometry.");
3361  PG_FREE_IF_COPY(input, 0);
3362  PG_RETURN_NULL();
3363  }
3364 
3365  lwgeom_result = lwgeom_voronoi_diagram(lwgeom_input, custom_clip_envelope ? &clip_envelope : NULL, tolerance, !return_polygons);
3366  lwgeom_free(lwgeom_input);
3367 
3368  if (!lwgeom_result)
3369  {
3370  lwpgerror("Error computing Voronoi diagram.");
3371  PG_FREE_IF_COPY(input, 0);
3372  PG_RETURN_NULL();
3373  }
3374 
3375  result = geometry_serialize(lwgeom_result);
3376  lwgeom_free(lwgeom_result);
3377 
3378  PG_FREE_IF_COPY(input, 0);
3379  PG_RETURN_POINTER(result);
3380 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
Definition: g_serialized.c:640
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
LWGEOM * lwgeom_voronoi_diagram(const LWGEOM *g, const GBOX *env, double tolerance, int output_edges)
Take vertices of a geometry and build the Voronoi diagram.
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)

References geometry_serialize(), gserialized_get_gbox_p(), lwgeom_free(), lwgeom_from_gserialized(), and lwgeom_voronoi_diagram().

Here is the call graph for this function: