PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

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

3321 {
3322  GSERIALIZED* input;
3323  GSERIALIZED* clip;
3324  GSERIALIZED* result;
3325  LWGEOM* lwgeom_input;
3326  LWGEOM* lwgeom_result;
3327  double tolerance;
3328  GBOX clip_envelope;
3329  int custom_clip_envelope;
3330  int return_polygons;
3331 
3332  /* Return NULL on NULL geometry */
3333  if (PG_ARGISNULL(0))
3334  PG_RETURN_NULL();
3335 
3336  /* Read our tolerance value */
3337  if (PG_ARGISNULL(2))
3338  {
3339  lwpgerror("Tolerance must be a positive number.");
3340  PG_RETURN_NULL();
3341  }
3342 
3343  tolerance = PG_GETARG_FLOAT8(2);
3344 
3345  if (tolerance < 0)
3346  {
3347  lwpgerror("Tolerance must be a positive number.");
3348  PG_RETURN_NULL();
3349  }
3350 
3351  /* Are we returning lines or polygons? */
3352  if (PG_ARGISNULL(3))
3353  {
3354  lwpgerror("return_polygons must be true or false.");
3355  PG_RETURN_NULL();
3356  }
3357  return_polygons = PG_GETARG_BOOL(3);
3358 
3359  /* Read our clipping envelope, if applicable. */
3360  custom_clip_envelope = !PG_ARGISNULL(1);
3361  if (custom_clip_envelope) {
3362  clip = PG_GETARG_GSERIALIZED_P(1);
3363  if (!gserialized_get_gbox_p(clip, &clip_envelope))
3364  {
3365  lwpgerror("Could not determine envelope of clipping geometry.");
3366  PG_FREE_IF_COPY(clip, 1);
3367  PG_RETURN_NULL();
3368  }
3369  PG_FREE_IF_COPY(clip, 1);
3370  }
3371 
3372  /* Read our input geometry */
3373  input = PG_GETARG_GSERIALIZED_P(0);
3374 
3375  lwgeom_input = lwgeom_from_gserialized(input);
3376 
3377  if(!lwgeom_input)
3378  {
3379  lwpgerror("Could not read input geometry.");
3380  PG_FREE_IF_COPY(input, 0);
3381  PG_RETURN_NULL();
3382  }
3383 
3384  lwgeom_result = lwgeom_voronoi_diagram(lwgeom_input, custom_clip_envelope ? &clip_envelope : NULL, tolerance, !return_polygons);
3385  lwgeom_free(lwgeom_input);
3386 
3387  if (!lwgeom_result)
3388  {
3389  lwpgerror("Error computing Voronoi diagram.");
3390  PG_FREE_IF_COPY(input, 0);
3391  PG_RETURN_NULL();
3392  }
3393 
3394  result = geometry_serialize(lwgeom_result);
3395  lwgeom_free(lwgeom_result);
3396 
3397  PG_FREE_IF_COPY(input, 0);
3398  PG_RETURN_POINTER(result);
3399 }
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Read the box from the GSERIALIZED or calculate it if necessary.
Definition: gserialized.c:65
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
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: