PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ BOX2D_construct()

Datum BOX2D_construct ( PG_FUNCTION_ARGS  )

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

526 {
527  GSERIALIZED *pgmin = PG_GETARG_GSERIALIZED_P(0);
528  GSERIALIZED *pgmax = PG_GETARG_GSERIALIZED_P(1);
529  GBOX *result;
530  LWPOINT *minpoint, *maxpoint;
531  double min, max, tmp;
532 
533  minpoint = (LWPOINT*)lwgeom_from_gserialized(pgmin);
534  maxpoint = (LWPOINT*)lwgeom_from_gserialized(pgmax);
535 
536  if ( (minpoint->type != POINTTYPE) || (maxpoint->type != POINTTYPE) )
537  {
538  elog(ERROR, "GBOX_construct: arguments must be points");
539  PG_RETURN_NULL();
540  }
541 
542  error_if_srid_mismatch(minpoint->srid, maxpoint->srid);
543 
544  result = gbox_new(gflags(0, 0, 0));
545 
546  /* Process X min/max */
547  min = lwpoint_get_x(minpoint);
548  max = lwpoint_get_x(maxpoint);
549  if ( min > max )
550  {
551  tmp = min;
552  min = max;
553  max = tmp;
554  }
555  result->xmin = min;
556  result->xmax = max;
557 
558  /* Process Y min/max */
559  min = lwpoint_get_y(minpoint);
560  max = lwpoint_get_y(maxpoint);
561  if ( min > max )
562  {
563  tmp = min;
564  min = max;
565  max = tmp;
566  }
567  result->ymin = min;
568  result->ymax = max;
569 
570  PG_RETURN_POINTER(result);
571 }
GBOX * gbox_new(uint8_t flags)
Create a new gbox with the dimensionality indicated by the flags.
Definition: g_box.c:39
uint8_t type
Definition: liblwgeom.h:409
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
double xmax
Definition: liblwgeom.h:295
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:336
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:63
double ymin
Definition: liblwgeom.h:296
double xmin
Definition: liblwgeom.h:294
double ymax
Definition: liblwgeom.h:297
int32_t srid
Definition: liblwgeom.h:412
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:84
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: