PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ ST_Voronoi()

Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

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

References geometry_serialize(), gserialized_get_gbox_p(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_voronoi_diagram(), PG_FUNCTION_INFO_V1(), POSTGIS_GEOS_VERSION, and ST_MinimumClearance().

Referenced by ST_Node().

3605 {
3606 #if POSTGIS_GEOS_VERSION < 35
3607  lwpgerror("The GEOS version this PostGIS binary "
3608  "was compiled against (%d) doesn't support "
3609  "'ST_Voronoi' function (3.5.0+ required)",
3611  PG_RETURN_NULL();
3612 #else /* POSTGIS_GEOS_VERSION >= 35 */
3613  GSERIALIZED* input;
3614  GSERIALIZED* clip;
3615  GSERIALIZED* result;
3616  LWGEOM* lwgeom_input;
3617  LWGEOM* lwgeom_result;
3618  double tolerance;
3619  GBOX clip_envelope;
3620  int custom_clip_envelope;
3621  int return_polygons;
3622 
3623  /* Return NULL on NULL geometry */
3624  if (PG_ARGISNULL(0))
3625  PG_RETURN_NULL();
3626 
3627  /* Read our tolerance value */
3628  if (PG_ARGISNULL(2))
3629  {
3630  lwpgerror("Tolerance must be a positive number.");
3631  PG_RETURN_NULL();
3632  }
3633 
3634  tolerance = PG_GETARG_FLOAT8(2);
3635 
3636  if (tolerance < 0)
3637  {
3638  lwpgerror("Tolerance must be a positive number.");
3639  PG_RETURN_NULL();
3640  }
3641 
3642  /* Are we returning lines or polygons? */
3643  if (PG_ARGISNULL(3))
3644  {
3645  lwpgerror("return_polygons must be true or false.");
3646  PG_RETURN_NULL();
3647  }
3648  return_polygons = PG_GETARG_BOOL(3);
3649 
3650  /* Read our clipping envelope, if applicable. */
3651  custom_clip_envelope = !PG_ARGISNULL(1);
3652  if (custom_clip_envelope) {
3653  clip = PG_GETARG_GSERIALIZED_P(1);
3654  if (!gserialized_get_gbox_p(clip, &clip_envelope))
3655  {
3656  lwpgerror("Could not determine envelope of clipping geometry.");
3657  PG_FREE_IF_COPY(clip, 1);
3658  PG_RETURN_NULL();
3659  }
3660  PG_FREE_IF_COPY(clip, 1);
3661  }
3662 
3663  /* Read our input geometry */
3664  input = PG_GETARG_GSERIALIZED_P(0);
3665 
3666  lwgeom_input = lwgeom_from_gserialized(input);
3667 
3668  if(!lwgeom_input)
3669  {
3670  lwpgerror("Could not read input geometry.");
3671  PG_FREE_IF_COPY(input, 0);
3672  PG_RETURN_NULL();
3673  }
3674 
3675  lwgeom_result = lwgeom_voronoi_diagram(lwgeom_input, custom_clip_envelope ? &clip_envelope : NULL, tolerance, !return_polygons);
3676  lwgeom_free(lwgeom_input);
3677 
3678  if (!lwgeom_result)
3679  {
3680  lwpgerror("Error computing Voronoi diagram.");
3681  PG_FREE_IF_COPY(input, 0);
3682  PG_RETURN_NULL();
3683  }
3684 
3685  result = geometry_serialize(lwgeom_result);
3686  lwgeom_free(lwgeom_result);
3687 
3688  PG_FREE_IF_COPY(input, 0);
3689  PG_RETURN_POINTER(result);
3690 
3691 #endif /* POSTGIS_GEOS_VERSION >= 35 */
3692 }
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
Definition: g_serialized.c:642
#define POSTGIS_GEOS_VERSION
Definition: sqldefines.h:10
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
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.
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
Here is the call graph for this function:
Here is the caller graph for this function: