PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ BOX2D_construct()

Datum BOX2D_construct ( PG_FUNCTION_ARGS  )

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

528 {
529  GSERIALIZED *pgmin = PG_GETARG_GSERIALIZED_P(0);
530  GSERIALIZED *pgmax = PG_GETARG_GSERIALIZED_P(1);
531  GBOX *result;
532  LWPOINT *minpoint, *maxpoint;
533  double min, max, tmp;
534 
535  minpoint = (LWPOINT*)lwgeom_from_gserialized(pgmin);
536  maxpoint = (LWPOINT*)lwgeom_from_gserialized(pgmax);
537 
538  if ( (minpoint->type != POINTTYPE) || (maxpoint->type != POINTTYPE) )
539  {
540  elog(ERROR, "GBOX_construct: arguments must be points");
541  PG_RETURN_NULL();
542  }
543 
544  error_if_srid_mismatch(minpoint->srid, maxpoint->srid);
545 
546  result = gbox_new(gflags(0, 0, 0));
547 
548  /* Process X min/max */
549  min = lwpoint_get_x(minpoint);
550  max = lwpoint_get_x(maxpoint);
551  if ( min > max )
552  {
553  tmp = min;
554  min = max;
555  max = tmp;
556  }
557  result->xmin = min;
558  result->xmax = max;
559 
560  /* Process Y min/max */
561  min = lwpoint_get_y(minpoint);
562  max = lwpoint_get_y(maxpoint);
563  if ( min > max )
564  {
565  tmp = min;
566  min = max;
567  max = tmp;
568  }
569  result->ymin = min;
570  result->ymax = max;
571 
572  PG_RETURN_POINTER(result);
573 }
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:338
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: