PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

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

3519 {
3520  GSERIALIZED* input;
3521  GSERIALIZED* clip;
3523  LWGEOM* lwgeom_input;
3524  LWGEOM* lwgeom_result;
3525  double tolerance;
3526  GBOX clip_envelope;
3527  int custom_clip_envelope;
3528  int return_polygons;
3529 
3530  /* Return NULL on NULL geometry */
3531  if (PG_ARGISNULL(0))
3532  PG_RETURN_NULL();
3533 
3534  /* Read our tolerance value */
3535  if (PG_ARGISNULL(2))
3536  {
3537  lwpgerror("Tolerance must be a positive number.");
3538  PG_RETURN_NULL();
3539  }
3540 
3541  tolerance = PG_GETARG_FLOAT8(2);
3542 
3543  if (tolerance < 0)
3544  {
3545  lwpgerror("Tolerance must be a positive number.");
3546  PG_RETURN_NULL();
3547  }
3548 
3549  /* Are we returning lines or polygons? */
3550  if (PG_ARGISNULL(3))
3551  {
3552  lwpgerror("return_polygons must be true or false.");
3553  PG_RETURN_NULL();
3554  }
3555  return_polygons = PG_GETARG_BOOL(3);
3556 
3557  /* Read our clipping envelope, if applicable. */
3558  custom_clip_envelope = !PG_ARGISNULL(1);
3559  if (custom_clip_envelope) {
3560  clip = PG_GETARG_GSERIALIZED_P(1);
3561  if (!gserialized_get_gbox_p(clip, &clip_envelope))
3562  {
3563  lwpgerror("Could not determine envelope of clipping geometry.");
3564  PG_FREE_IF_COPY(clip, 1);
3565  PG_RETURN_NULL();
3566  }
3567  PG_FREE_IF_COPY(clip, 1);
3568  }
3569 
3570  /* Read our input geometry */
3571  input = PG_GETARG_GSERIALIZED_P(0);
3572 
3573  lwgeom_input = lwgeom_from_gserialized(input);
3574 
3575  if(!lwgeom_input)
3576  {
3577  lwpgerror("Could not read input geometry.");
3578  PG_FREE_IF_COPY(input, 0);
3579  PG_RETURN_NULL();
3580  }
3581 
3582  lwgeom_result = lwgeom_voronoi_diagram(lwgeom_input, custom_clip_envelope ? &clip_envelope : NULL, tolerance, !return_polygons);
3583  lwgeom_free(lwgeom_input);
3584 
3585  if (!lwgeom_result)
3586  {
3587  lwpgerror("Error computing Voronoi diagram.");
3588  PG_FREE_IF_COPY(input, 0);
3589  PG_RETURN_NULL();
3590  }
3591 
3592  result = geometry_serialize(lwgeom_result);
3593  lwgeom_free(lwgeom_result);
3594 
3595  PG_FREE_IF_COPY(input, 0);
3596  PG_RETURN_POINTER(result);
3597 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
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:1155
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.

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

Here is the call graph for this function: