PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ BOX2D_combine()

Datum BOX2D_combine ( PG_FUNCTION_ARGS  )

Definition at line 385 of file lwgeom_box.c.

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

Referenced by BOX2D_to_BOX3D().

386 {
387  Pointer box2d_ptr = PG_GETARG_POINTER(0);
388  Pointer geom_ptr = PG_GETARG_POINTER(1);
389  GBOX *a,*b;
390  GSERIALIZED *lwgeom;
391  GBOX box, *result;
392 
393  if ( (box2d_ptr == NULL) && (geom_ptr == NULL) )
394  {
395  PG_RETURN_NULL(); /* combine_box2d(null,null) => null */
396  }
397 
398  result = (GBOX *)palloc(sizeof(GBOX));
399 
400  if (box2d_ptr == NULL)
401  {
402  lwgeom = PG_GETARG_GSERIALIZED_P(1);
403  /* empty geom would make getbox2d_p return NULL */
404  if ( ! gserialized_get_gbox_p(lwgeom, &box) ) PG_RETURN_NULL();
405  memcpy(result, &box, sizeof(GBOX));
406  PG_RETURN_POINTER(result);
407  }
408 
409  /* combine_bbox(BOX3D, null) => BOX3D */
410  if (geom_ptr == NULL)
411  {
412  memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(GBOX));
413  PG_RETURN_POINTER(result);
414  }
415 
416  /*combine_bbox(BOX3D, geometry) => union(BOX3D, geometry->bvol) */
417 
418  lwgeom = PG_GETARG_GSERIALIZED_P(1);
419  if ( ! gserialized_get_gbox_p(lwgeom, &box) )
420  {
421  /* must be the empty geom */
422  memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(GBOX));
423  PG_RETURN_POINTER(result);
424  }
425 
426  a = (GBOX *)PG_GETARG_DATUM(0);
427  b = &box;
428 
429  result->xmax = Max(a->xmax, b->xmax);
430  result->ymax = Max(a->ymax, b->ymax);
431  result->xmin = Min(a->xmin, b->xmin);
432  result->ymin = Min(a->ymin, b->ymin);
433 
434  PG_RETURN_POINTER(result);
435 }
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:371
double xmax
Definition: liblwgeom.h:277
double ymin
Definition: liblwgeom.h:278
double xmin
Definition: liblwgeom.h:276
double ymax
Definition: liblwgeom.h:279
Here is the call graph for this function:
Here is the caller graph for this function: