PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

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

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