PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

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

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