PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

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

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