PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

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

3423 {
3424  GSERIALIZED* input;
3425  GSERIALIZED* clip;
3427  LWGEOM* lwgeom_input;
3428  LWGEOM* lwgeom_result;
3429  double tolerance;
3430  GBOX clip_envelope;
3431  int custom_clip_envelope;
3432  int return_polygons;
3433 
3434  /* Return NULL on NULL geometry */
3435  if (PG_ARGISNULL(0))
3436  PG_RETURN_NULL();
3437 
3438  /* Read our tolerance value */
3439  if (PG_ARGISNULL(2))
3440  {
3441  lwpgerror("Tolerance must be a positive number.");
3442  PG_RETURN_NULL();
3443  }
3444 
3445  tolerance = PG_GETARG_FLOAT8(2);
3446 
3447  if (tolerance < 0)
3448  {
3449  lwpgerror("Tolerance must be a positive number.");
3450  PG_RETURN_NULL();
3451  }
3452 
3453  /* Are we returning lines or polygons? */
3454  if (PG_ARGISNULL(3))
3455  {
3456  lwpgerror("return_polygons must be true or false.");
3457  PG_RETURN_NULL();
3458  }
3459  return_polygons = PG_GETARG_BOOL(3);
3460 
3461  /* Read our clipping envelope, if applicable. */
3462  custom_clip_envelope = !PG_ARGISNULL(1);
3463  if (custom_clip_envelope) {
3464  clip = PG_GETARG_GSERIALIZED_P(1);
3465  if (!gserialized_get_gbox_p(clip, &clip_envelope))
3466  {
3467  lwpgerror("Could not determine envelope of clipping geometry.");
3468  PG_FREE_IF_COPY(clip, 1);
3469  PG_RETURN_NULL();
3470  }
3471  PG_FREE_IF_COPY(clip, 1);
3472  }
3473 
3474  /* Read our input geometry */
3475  input = PG_GETARG_GSERIALIZED_P(0);
3476 
3477  lwgeom_input = lwgeom_from_gserialized(input);
3478 
3479  if(!lwgeom_input)
3480  {
3481  lwpgerror("Could not read input geometry.");
3482  PG_FREE_IF_COPY(input, 0);
3483  PG_RETURN_NULL();
3484  }
3485 
3486  lwgeom_result = lwgeom_voronoi_diagram(lwgeom_input, custom_clip_envelope ? &clip_envelope : NULL, tolerance, !return_polygons);
3487  lwgeom_free(lwgeom_input);
3488 
3489  if (!lwgeom_result)
3490  {
3491  lwpgerror("Error computing Voronoi diagram.");
3492  PG_FREE_IF_COPY(input, 0);
3493  PG_RETURN_NULL();
3494  }
3495 
3496  result = geometry_serialize(lwgeom_result);
3497  lwgeom_free(lwgeom_result);
3498 
3499  PG_FREE_IF_COPY(input, 0);
3500  PG_RETURN_POINTER(result);
3501 }
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: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: