PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ BOX2D_construct()

Datum BOX2D_construct ( PG_FUNCTION_ARGS  )

Definition at line 535 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().

536 {
537  GSERIALIZED *pgmin = PG_GETARG_GSERIALIZED_P(0);
538  GSERIALIZED *pgmax = PG_GETARG_GSERIALIZED_P(1);
539  GBOX *result;
540  LWPOINT *minpoint, *maxpoint;
541  double min, max, tmp;
542 
543  minpoint = (LWPOINT*)lwgeom_from_gserialized(pgmin);
544  maxpoint = (LWPOINT*)lwgeom_from_gserialized(pgmax);
545 
546  if ( (minpoint->type != POINTTYPE) || (maxpoint->type != POINTTYPE) )
547  {
548  elog(ERROR, "GBOX_construct: arguments must be points");
549  PG_RETURN_NULL();
550  }
551 
552  error_if_srid_mismatch(minpoint->srid, maxpoint->srid);
553 
554  result = gbox_new(gflags(0, 0, 0));
555 
556  /* Process X min/max */
557  min = lwpoint_get_x(minpoint);
558  max = lwpoint_get_x(maxpoint);
559  if ( min > max )
560  {
561  tmp = min;
562  min = max;
563  max = tmp;
564  }
565  result->xmin = min;
566  result->xmax = max;
567 
568  /* Process Y min/max */
569  min = lwpoint_get_y(minpoint);
570  max = lwpoint_get_y(maxpoint);
571  if ( min > max )
572  {
573  tmp = min;
574  min = max;
575  max = tmp;
576  }
577  result->ymin = min;
578  result->ymax = max;
579 
580  PG_RETURN_POINTER(result);
581 }
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
Definition: g_box.c:43
uint8_t type
Definition: liblwgeom.h:407
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
double xmax
Definition: liblwgeom.h:293
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:371
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:63
double ymin
Definition: liblwgeom.h:294
double xmin
Definition: liblwgeom.h:292
double ymax
Definition: liblwgeom.h:295
int32_t srid
Definition: liblwgeom.h:410
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:145
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:76
Here is the call graph for this function:
Here is the caller graph for this function: