PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

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

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