PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum ST_Voronoi ( PG_FUNCTION_ARGS  )

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

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

3456 {
3457 #if POSTGIS_GEOS_VERSION < 35
3458  lwpgerror("The GEOS version this PostGIS binary "
3459  "was compiled against (%d) doesn't support "
3460  "'ST_Voronoi' function (3.5.0+ required)",
3462  PG_RETURN_NULL();
3463 #else /* POSTGIS_GEOS_VERSION >= 35 */
3464  GSERIALIZED* input;
3465  GSERIALIZED* clip;
3466  GSERIALIZED* result;
3467  LWGEOM* lwgeom_input;
3468  LWGEOM* lwgeom_result;
3469  double tolerance;
3470  GBOX clip_envelope;
3471  int custom_clip_envelope;
3472  int return_polygons;
3473 
3474  /* Return NULL on NULL geometry */
3475  if (PG_ARGISNULL(0))
3476  PG_RETURN_NULL();
3477 
3478  /* Read our tolerance value */
3479  if (PG_ARGISNULL(2))
3480  {
3481  lwpgerror("Tolerance must be a positive number.");
3482  PG_RETURN_NULL();
3483  }
3484 
3485  tolerance = PG_GETARG_FLOAT8(2);
3486 
3487  if (tolerance < 0)
3488  {
3489  lwpgerror("Tolerance must be a positive number.");
3490  PG_RETURN_NULL();
3491  }
3492 
3493  /* Are we returning lines or polygons? */
3494  if (PG_ARGISNULL(3))
3495  {
3496  lwpgerror("return_polygons must be true or false.");
3497  PG_RETURN_NULL();
3498  }
3499  return_polygons = PG_GETARG_BOOL(3);
3500 
3501  /* Read our clipping envelope, if applicable. */
3502  custom_clip_envelope = !PG_ARGISNULL(1);
3503  if (custom_clip_envelope) {
3504  clip = PG_GETARG_GSERIALIZED_P(1);
3505  if (!gserialized_get_gbox_p(clip, &clip_envelope))
3506  {
3507  lwpgerror("Could not determine envelope of clipping geometry.");
3508  PG_FREE_IF_COPY(clip, 1);
3509  PG_RETURN_NULL();
3510  }
3511  PG_FREE_IF_COPY(clip, 1);
3512  }
3513 
3514  /* Read our input geometry */
3515  input = PG_GETARG_GSERIALIZED_P(0);
3516 
3517  lwgeom_input = lwgeom_from_gserialized(input);
3518 
3519  if(!lwgeom_input)
3520  {
3521  lwpgerror("Could not read input geometry.");
3522  PG_FREE_IF_COPY(input, 0);
3523  PG_RETURN_NULL();
3524  }
3525 
3526  lwgeom_result = lwgeom_voronoi_diagram(lwgeom_input, custom_clip_envelope ? &clip_envelope : NULL, tolerance, !return_polygons);
3527  lwgeom_free(lwgeom_input);
3528 
3529  if (!lwgeom_result)
3530  {
3531  lwpgerror("Error computing Voronoi diagram.");
3532  PG_FREE_IF_COPY(input, 0);
3533  PG_RETURN_NULL();
3534  }
3535 
3536  result = geometry_serialize(lwgeom_result);
3537  lwgeom_free(lwgeom_result);
3538 
3539  PG_FREE_IF_COPY(input, 0);
3540  PG_RETURN_POINTER(result);
3541 
3542 #endif /* POSTGIS_GEOS_VERSION >= 35 */
3543 }
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:639
#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:1137
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: