PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

Definition at line 3302 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().

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