PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum BOX2D_combine ( PG_FUNCTION_ARGS  )

Definition at line 365 of file lwgeom_box.c.

References gserialized_get_gbox_p(), result, GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

366 {
367  Pointer box2d_ptr = PG_GETARG_POINTER(0);
368  Pointer geom_ptr = PG_GETARG_POINTER(1);
369  GBOX *a,*b;
370  GSERIALIZED *lwgeom;
371  GBOX box, *result;
372 
373  if ( (box2d_ptr == NULL) && (geom_ptr == NULL) )
374  {
375  PG_RETURN_NULL(); /* combine_box2d(null,null) => null */
376  }
377 
378  result = (GBOX *)palloc(sizeof(GBOX));
379 
380  if (box2d_ptr == NULL)
381  {
382  lwgeom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
383  /* empty geom would make getbox2d_p return NULL */
384  if ( ! gserialized_get_gbox_p(lwgeom, &box) ) PG_RETURN_NULL();
385  memcpy(result, &box, sizeof(GBOX));
386  PG_RETURN_POINTER(result);
387  }
388 
389  /* combine_bbox(BOX3D, null) => BOX3D */
390  if (geom_ptr == NULL)
391  {
392  memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(GBOX));
393  PG_RETURN_POINTER(result);
394  }
395 
396  /*combine_bbox(BOX3D, geometry) => union(BOX3D, geometry->bvol) */
397 
398  lwgeom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
399  if ( ! gserialized_get_gbox_p(lwgeom, &box) )
400  {
401  /* must be the empty geom */
402  memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(GBOX));
403  PG_RETURN_POINTER(result);
404  }
405 
406  a = (GBOX *)PG_GETARG_DATUM(0);
407  b = &box;
408 
409  result->xmax = Max(a->xmax, b->xmax);
410  result->ymax = Max(a->ymax, b->ymax);
411  result->xmin = Min(a->xmin, b->xmin);
412  result->ymin = Min(a->ymin, b->ymin);
413 
414  PG_RETURN_POINTER(result);
415 }
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:373
double xmax
Definition: liblwgeom.h:249
char ** result
Definition: liblwgeom.h:218
double ymin
Definition: liblwgeom.h:250
double xmin
Definition: liblwgeom.h:248
double ymax
Definition: liblwgeom.h:251

Here is the call graph for this function: