PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ BOX2D_construct()

Datum BOX2D_construct ( PG_FUNCTION_ARGS  )

Definition at line 514 of file lwgeom_box.c.

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

Referenced by BOX2D_to_LWGEOM().

515 {
516  GSERIALIZED *pgmin = PG_GETARG_GSERIALIZED_P(0);
517  GSERIALIZED *pgmax = PG_GETARG_GSERIALIZED_P(1);
518  GBOX *result;
519  LWPOINT *minpoint, *maxpoint;
520  double min, max, tmp;
521 
522  minpoint = (LWPOINT*)lwgeom_from_gserialized(pgmin);
523  maxpoint = (LWPOINT*)lwgeom_from_gserialized(pgmax);
524 
525  if ( (minpoint->type != POINTTYPE) || (maxpoint->type != POINTTYPE) )
526  {
527  elog(ERROR, "GBOX_construct: arguments must be points");
528  PG_RETURN_NULL();
529  }
530 
531  error_if_srid_mismatch(minpoint->srid, maxpoint->srid);
532 
533  result = gbox_new(gflags(0, 0, 0));
534 
535  /* Process X min/max */
536  min = lwpoint_get_x(minpoint);
537  max = lwpoint_get_x(maxpoint);
538  if ( min > max )
539  {
540  tmp = min;
541  min = max;
542  max = tmp;
543  }
544  result->xmin = min;
545  result->xmax = max;
546 
547  /* Process Y min/max */
548  min = lwpoint_get_y(minpoint);
549  max = lwpoint_get_y(maxpoint);
550  if ( min > max )
551  {
552  tmp = min;
553  min = max;
554  max = tmp;
555  }
556  result->ymin = min;
557  result->ymax = max;
558 
559  PG_RETURN_POINTER(result);
560 }
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
Definition: g_box.c:28
uint8_t type
Definition: liblwgeom.h:391
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
double xmax
Definition: liblwgeom.h:277
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:341
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:50
double ymin
Definition: liblwgeom.h:278
double xmin
Definition: liblwgeom.h:276
double ymax
Definition: liblwgeom.h:279
int32_t srid
Definition: liblwgeom.h:394
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:130
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:60
Here is the call graph for this function:
Here is the caller graph for this function: