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

Definition at line 409 of file lwgeom_box.c.

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

410 {
411  Pointer box2d_ptr = PG_GETARG_POINTER(0);
412  Pointer geom_ptr = PG_GETARG_POINTER(1);
413  GBOX *a,*b;
414  GSERIALIZED *lwgeom;
415  GBOX box, *result;
416 
417  if ( (box2d_ptr == NULL) && (geom_ptr == NULL) )
418  {
419  PG_RETURN_NULL(); /* combine_box2d(null,null) => null */
420  }
421 
422  result = (GBOX *)palloc(sizeof(GBOX));
423 
424  if (box2d_ptr == NULL)
425  {
426  lwgeom = PG_GETARG_GSERIALIZED_P(1);
427  /* empty geom would make getbox2d_p return NULL */
428  if ( ! gserialized_get_gbox_p(lwgeom, &box) ) PG_RETURN_NULL();
429  memcpy(result, &box, sizeof(GBOX));
430  PG_RETURN_POINTER(result);
431  }
432 
433  /* combine_bbox(BOX3D, null) => BOX3D */
434  if (geom_ptr == NULL)
435  {
436  memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(GBOX));
437  PG_RETURN_POINTER(result);
438  }
439 
440  /*combine_bbox(BOX3D, geometry) => union(BOX3D, geometry->bvol) */
441 
442  lwgeom = PG_GETARG_GSERIALIZED_P(1);
443  if ( ! gserialized_get_gbox_p(lwgeom, &box) )
444  {
445  /* must be the empty geom */
446  memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(GBOX));
447  PG_RETURN_POINTER(result);
448  }
449 
450  a = (GBOX *)PG_GETARG_DATUM(0);
451  b = &box;
452 
453  result->xmax = Max(a->xmax, b->xmax);
454  result->ymax = Max(a->ymax, b->ymax);
455  result->xmin = Min(a->xmin, b->xmin);
456  result->ymin = Min(a->ymin, b->ymin);
457 
458  PG_RETURN_POINTER(result);
459 }
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
void * Pointer
Definition: kmeans.h:59
double xmax
Definition: liblwgeom.h:292
double ymin
Definition: liblwgeom.h:293
double xmin
Definition: liblwgeom.h:291
double ymax
Definition: liblwgeom.h:294

Here is the call graph for this function: