PostGIS  3.6.1dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

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

2495 {
2496  GSERIALIZED* input;
2497  GSERIALIZED* clip;
2499  LWGEOM* lwgeom_input;
2500  LWGEOM* lwgeom_result;
2501  double tolerance;
2502  GBOX clip_envelope;
2503  int custom_clip_envelope;
2504  int return_polygons;
2505 
2506  /* Return NULL on NULL geometry */
2507  if (PG_ARGISNULL(0))
2508  PG_RETURN_NULL();
2509 
2510  /* Read our tolerance value */
2511  if (PG_ARGISNULL(2))
2512  {
2513  lwpgerror("Tolerance must be a positive number.");
2514  PG_RETURN_NULL();
2515  }
2516 
2517  tolerance = PG_GETARG_FLOAT8(2);
2518 
2519  if (tolerance < 0)
2520  {
2521  lwpgerror("Tolerance must be a positive number.");
2522  PG_RETURN_NULL();
2523  }
2524 
2525  /* Are we returning lines or polygons? */
2526  if (PG_ARGISNULL(3))
2527  {
2528  lwpgerror("return_polygons must be true or false.");
2529  PG_RETURN_NULL();
2530  }
2531  return_polygons = PG_GETARG_BOOL(3);
2532 
2533  /* Read our clipping envelope, if applicable. */
2534  custom_clip_envelope = !PG_ARGISNULL(1);
2535  if (custom_clip_envelope) {
2536  clip = PG_GETARG_GSERIALIZED_P(1);
2537  if (!gserialized_get_gbox_p(clip, &clip_envelope))
2538  {
2539  lwpgerror("Could not determine envelope of clipping geometry.");
2540  PG_FREE_IF_COPY(clip, 1);
2541  PG_RETURN_NULL();
2542  }
2543  PG_FREE_IF_COPY(clip, 1);
2544  }
2545 
2546  /* Read our input geometry */
2547  input = PG_GETARG_GSERIALIZED_P(0);
2548 
2549  lwgeom_input = lwgeom_from_gserialized(input);
2550 
2551  if(!lwgeom_input)
2552  {
2553  lwpgerror("Could not read input geometry.");
2554  PG_FREE_IF_COPY(input, 0);
2555  PG_RETURN_NULL();
2556  }
2557 
2558  lwgeom_result = lwgeom_voronoi_diagram(lwgeom_input, custom_clip_envelope ? &clip_envelope : NULL, tolerance, !return_polygons);
2559  lwgeom_free(lwgeom_input);
2560 
2561  if (!lwgeom_result)
2562  {
2563  lwpgerror("Error computing Voronoi diagram.");
2564  PG_FREE_IF_COPY(input, 0);
2565  PG_RETURN_NULL();
2566  }
2567 
2568  result = geometry_serialize(lwgeom_result);
2569  lwgeom_free(lwgeom_result);
2570 
2571  PG_FREE_IF_COPY(input, 0);
2572  PG_RETURN_POINTER(result);
2573 }
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:94
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
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: