2495{
2501 double tolerance;
2503 int custom_clip_envelope;
2504 int return_polygons;
2505
2506
2507 if (PG_ARGISNULL(0))
2508 PG_RETURN_NULL();
2509
2510
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
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
2534 custom_clip_envelope = !PG_ARGISNULL(1);
2535 if (custom_clip_envelope) {
2536 clip = PG_GETARG_GSERIALIZED_P(1);
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
2547 input = PG_GETARG_GSERIALIZED_P(0);
2548
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);
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);
2570
2571 PG_FREE_IF_COPY(input, 0);
2572 PG_RETURN_POINTER(
result);
2573}
char result[OUT_DOUBLE_BUFFER_SIZE]
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Read the box from the GSERIALIZED or calculate it if necessary.
void lwgeom_free(LWGEOM *geom)
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.