PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

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

3479 {
3480  GSERIALIZED* input;
3481  GSERIALIZED* clip;
3483  LWGEOM* lwgeom_input;
3484  LWGEOM* lwgeom_result;
3485  double tolerance;
3486  GBOX clip_envelope;
3487  int custom_clip_envelope;
3488  int return_polygons;
3489 
3490  /* Return NULL on NULL geometry */
3491  if (PG_ARGISNULL(0))
3492  PG_RETURN_NULL();
3493 
3494  /* Read our tolerance value */
3495  if (PG_ARGISNULL(2))
3496  {
3497  lwpgerror("Tolerance must be a positive number.");
3498  PG_RETURN_NULL();
3499  }
3500 
3501  tolerance = PG_GETARG_FLOAT8(2);
3502 
3503  if (tolerance < 0)
3504  {
3505  lwpgerror("Tolerance must be a positive number.");
3506  PG_RETURN_NULL();
3507  }
3508 
3509  /* Are we returning lines or polygons? */
3510  if (PG_ARGISNULL(3))
3511  {
3512  lwpgerror("return_polygons must be true or false.");
3513  PG_RETURN_NULL();
3514  }
3515  return_polygons = PG_GETARG_BOOL(3);
3516 
3517  /* Read our clipping envelope, if applicable. */
3518  custom_clip_envelope = !PG_ARGISNULL(1);
3519  if (custom_clip_envelope) {
3520  clip = PG_GETARG_GSERIALIZED_P(1);
3521  if (!gserialized_get_gbox_p(clip, &clip_envelope))
3522  {
3523  lwpgerror("Could not determine envelope of clipping geometry.");
3524  PG_FREE_IF_COPY(clip, 1);
3525  PG_RETURN_NULL();
3526  }
3527  PG_FREE_IF_COPY(clip, 1);
3528  }
3529 
3530  /* Read our input geometry */
3531  input = PG_GETARG_GSERIALIZED_P(0);
3532 
3533  lwgeom_input = lwgeom_from_gserialized(input);
3534 
3535  if(!lwgeom_input)
3536  {
3537  lwpgerror("Could not read input geometry.");
3538  PG_FREE_IF_COPY(input, 0);
3539  PG_RETURN_NULL();
3540  }
3541 
3542  lwgeom_result = lwgeom_voronoi_diagram(lwgeom_input, custom_clip_envelope ? &clip_envelope : NULL, tolerance, !return_polygons);
3543  lwgeom_free(lwgeom_input);
3544 
3545  if (!lwgeom_result)
3546  {
3547  lwpgerror("Error computing Voronoi diagram.");
3548  PG_FREE_IF_COPY(input, 0);
3549  PG_RETURN_NULL();
3550  }
3551 
3552  result = geometry_serialize(lwgeom_result);
3553  lwgeom_free(lwgeom_result);
3554 
3555  PG_FREE_IF_COPY(input, 0);
3556  PG_RETURN_POINTER(result);
3557 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
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.

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

Here is the call graph for this function: