PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

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

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

Referenced by ST_Node().

3305 {
3306  GSERIALIZED* input;
3307  GSERIALIZED* clip;
3308  GSERIALIZED* result;
3309  LWGEOM* lwgeom_input;
3310  LWGEOM* lwgeom_result;
3311  double tolerance;
3312  GBOX clip_envelope;
3313  int custom_clip_envelope;
3314  int return_polygons;
3315 
3316  /* Return NULL on NULL geometry */
3317  if (PG_ARGISNULL(0))
3318  PG_RETURN_NULL();
3319 
3320  /* Read our tolerance value */
3321  if (PG_ARGISNULL(2))
3322  {
3323  lwpgerror("Tolerance must be a positive number.");
3324  PG_RETURN_NULL();
3325  }
3326 
3327  tolerance = PG_GETARG_FLOAT8(2);
3328 
3329  if (tolerance < 0)
3330  {
3331  lwpgerror("Tolerance must be a positive number.");
3332  PG_RETURN_NULL();
3333  }
3334 
3335  /* Are we returning lines or polygons? */
3336  if (PG_ARGISNULL(3))
3337  {
3338  lwpgerror("return_polygons must be true or false.");
3339  PG_RETURN_NULL();
3340  }
3341  return_polygons = PG_GETARG_BOOL(3);
3342 
3343  /* Read our clipping envelope, if applicable. */
3344  custom_clip_envelope = !PG_ARGISNULL(1);
3345  if (custom_clip_envelope) {
3346  clip = PG_GETARG_GSERIALIZED_P(1);
3347  if (!gserialized_get_gbox_p(clip, &clip_envelope))
3348  {
3349  lwpgerror("Could not determine envelope of clipping geometry.");
3350  PG_FREE_IF_COPY(clip, 1);
3351  PG_RETURN_NULL();
3352  }
3353  PG_FREE_IF_COPY(clip, 1);
3354  }
3355 
3356  /* Read our input geometry */
3357  input = PG_GETARG_GSERIALIZED_P(0);
3358 
3359  lwgeom_input = lwgeom_from_gserialized(input);
3360 
3361  if(!lwgeom_input)
3362  {
3363  lwpgerror("Could not read input geometry.");
3364  PG_FREE_IF_COPY(input, 0);
3365  PG_RETURN_NULL();
3366  }
3367 
3368  lwgeom_result = lwgeom_voronoi_diagram(lwgeom_input, custom_clip_envelope ? &clip_envelope : NULL, tolerance, !return_polygons);
3369  lwgeom_free(lwgeom_input);
3370 
3371  if (!lwgeom_result)
3372  {
3373  lwpgerror("Error computing Voronoi diagram.");
3374  PG_FREE_IF_COPY(input, 0);
3375  PG_RETURN_NULL();
3376  }
3377 
3378  result = geometry_serialize(lwgeom_result);
3379  lwgeom_free(lwgeom_result);
3380 
3381  PG_FREE_IF_COPY(input, 0);
3382  PG_RETURN_POINTER(result);
3383 }
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:639
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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)
Here is the call graph for this function:
Here is the caller graph for this function: