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

Definition at line 3533 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.

3534 {
3535 #if POSTGIS_GEOS_VERSION < 35
3536  lwpgerror("The GEOS version this PostGIS binary "
3537  "was compiled against (%d) doesn't support "
3538  "'ST_Voronoi' function (3.5.0+ required)",
3540  PG_RETURN_NULL();
3541 #else /* POSTGIS_GEOS_VERSION >= 35 */
3542  GSERIALIZED* input;
3543  GSERIALIZED* clip;
3544  GSERIALIZED* result;
3545  LWGEOM* lwgeom_input;
3546  LWGEOM* lwgeom_result;
3547  double tolerance;
3548  GBOX clip_envelope;
3549  int custom_clip_envelope;
3550  int return_polygons;
3551 
3552  /* Return NULL on NULL geometry */
3553  if (PG_ARGISNULL(0))
3554  PG_RETURN_NULL();
3555 
3556  /* Read our tolerance value */
3557  if (PG_ARGISNULL(2))
3558  {
3559  lwpgerror("Tolerance must be a positive number.");
3560  PG_RETURN_NULL();
3561  }
3562 
3563  tolerance = PG_GETARG_FLOAT8(2);
3564 
3565  if (tolerance < 0)
3566  {
3567  lwpgerror("Tolerance must be a positive number.");
3568  PG_RETURN_NULL();
3569  }
3570 
3571  /* Are we returning lines or polygons? */
3572  if (PG_ARGISNULL(3))
3573  {
3574  lwpgerror("return_polygons must be true or false.");
3575  PG_RETURN_NULL();
3576  }
3577  return_polygons = PG_GETARG_BOOL(3);
3578 
3579  /* Read our clipping envelope, if applicable. */
3580  custom_clip_envelope = !PG_ARGISNULL(1);
3581  if (custom_clip_envelope) {
3582  clip = PG_GETARG_GSERIALIZED_P(1);
3583  if (!gserialized_get_gbox_p(clip, &clip_envelope))
3584  {
3585  lwpgerror("Could not determine envelope of clipping geometry.");
3586  PG_FREE_IF_COPY(clip, 1);
3587  PG_RETURN_NULL();
3588  }
3589  PG_FREE_IF_COPY(clip, 1);
3590  }
3591 
3592  /* Read our input geometry */
3593  input = PG_GETARG_GSERIALIZED_P(0);
3594 
3595  lwgeom_input = lwgeom_from_gserialized(input);
3596 
3597  if(!lwgeom_input)
3598  {
3599  lwpgerror("Could not read input geometry.");
3600  PG_FREE_IF_COPY(input, 0);
3601  PG_RETURN_NULL();
3602  }
3603 
3604  lwgeom_result = lwgeom_voronoi_diagram(lwgeom_input, custom_clip_envelope ? &clip_envelope : NULL, tolerance, !return_polygons);
3605  lwgeom_free(lwgeom_input);
3606 
3607  if (!lwgeom_result)
3608  {
3609  lwpgerror("Error computing Voronoi diagram.");
3610  PG_FREE_IF_COPY(input, 0);
3611  PG_RETURN_NULL();
3612  }
3613 
3614  result = geometry_serialize(lwgeom_result);
3615  lwgeom_free(lwgeom_result);
3616 
3617  PG_FREE_IF_COPY(input, 0);
3618  PG_RETURN_POINTER(result);
3619 
3620 #endif /* POSTGIS_GEOS_VERSION >= 35 */
3621 }
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:398
#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:1063
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: