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

Definition at line 494 of file lwgeom_box.c.

References error_if_srid_mismatch(), gbox_new(), gflags(), lwgeom_from_gserialized(), lwpoint_get_x(), lwpoint_get_y(), POINTTYPE, result, LWPOINT::srid, LWPOINT::type, GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

495 {
496  GSERIALIZED *pgmin = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
497  GSERIALIZED *pgmax = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
498  GBOX *result;
499  LWPOINT *minpoint, *maxpoint;
500  double min, max, tmp;
501 
502  minpoint = (LWPOINT*)lwgeom_from_gserialized(pgmin);
503  maxpoint = (LWPOINT*)lwgeom_from_gserialized(pgmax);
504 
505  if ( (minpoint->type != POINTTYPE) || (maxpoint->type != POINTTYPE) )
506  {
507  elog(ERROR, "GBOX_construct: arguments must be points");
508  PG_RETURN_NULL();
509  }
510 
511  error_if_srid_mismatch(minpoint->srid, maxpoint->srid);
512 
513  result = gbox_new(gflags(0, 0, 0));
514 
515  /* Process X min/max */
516  min = lwpoint_get_x(minpoint);
517  max = lwpoint_get_x(maxpoint);
518  if ( min > max )
519  {
520  tmp = min;
521  min = max;
522  max = tmp;
523  }
524  result->xmin = min;
525  result->xmax = max;
526 
527  /* Process Y min/max */
528  min = lwpoint_get_y(minpoint);
529  max = lwpoint_get_y(maxpoint);
530  if ( min > max )
531  {
532  tmp = min;
533  min = max;
534  max = tmp;
535  }
536  result->ymin = min;
537  result->ymax = max;
538 
539  PG_RETURN_POINTER(result);
540 }
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
Definition: g_box.c:26
uint8_t type
Definition: liblwgeom.h:363
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:317
double xmax
Definition: liblwgeom.h:249
char ** result
Definition: liblwgeom.h:218
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:48
double ymin
Definition: liblwgeom.h:250
double xmin
Definition: liblwgeom.h:248
double ymax
Definition: liblwgeom.h:251
int32_t srid
Definition: liblwgeom.h:366
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:131
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:58

Here is the call graph for this function: