PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

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

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