PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

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

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