PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ ST_BoundingDiagonal()

Datum ST_BoundingDiagonal ( PG_FUNCTION_ARGS  )

Definition at line 3019 of file lwgeom_functions_basic.c.

3020 {
3021  GSERIALIZED *geom_out;
3022  bool fits = PG_GETARG_BOOL(1);
3023  LWGEOM *lwgeom_out = NULL;
3024 
3025  GBOX gbox = {0};
3026  int hasz;
3027  int hasm;
3028  int32_t srid;
3029 
3030  POINT4D pt;
3031  POINTARRAY *pa;
3032 
3033  if (fits)
3034  {
3035  GSERIALIZED *geom_in = PG_GETARG_GSERIALIZED_P(0);
3036  LWGEOM *lwgeom_in = lwgeom_from_gserialized(geom_in);
3037  lwgeom_calculate_gbox(lwgeom_in, &gbox);
3038  hasz = FLAGS_GET_Z(lwgeom_in->flags);
3039  hasm = FLAGS_GET_M(lwgeom_in->flags);
3040  srid = lwgeom_in->srid;
3041  }
3042  else
3043  {
3044  uint8_t type;
3045  lwflags_t flags;
3046  int res = gserialized_datum_get_internals_p(PG_GETARG_DATUM(0), &gbox, &flags, &type, &srid);
3047  hasz = FLAGS_GET_Z(flags);
3048  hasm = FLAGS_GET_M(flags);
3049  if (res == LW_FAILURE)
3050  {
3051  lwgeom_out = lwgeom_construct_empty(LINETYPE, srid, hasz, hasm);
3052  }
3053  }
3054 
3055  if (!lwgeom_out)
3056  {
3057  pa = ptarray_construct_empty(hasz, hasm, 2);
3058  pt.x = gbox.xmin;
3059  pt.y = gbox.ymin;
3060  pt.z = gbox.zmin;
3061  pt.m = gbox.mmin;
3062  ptarray_append_point(pa, &pt, LW_TRUE);
3063  pt.x = gbox.xmax;
3064  pt.y = gbox.ymax;
3065  pt.z = gbox.zmax;
3066  pt.m = gbox.mmax;
3067  ptarray_append_point(pa, &pt, LW_TRUE);
3068  lwgeom_out = lwline_as_lwgeom(lwline_construct(srid, NULL, pa));
3069  }
3070 
3071  geom_out = geometry_serialize(lwgeom_out);
3072  lwgeom_free(lwgeom_out);
3073 
3074  PG_RETURN_POINTER(geom_out);
3075 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
int gserialized_datum_get_internals_p(Datum gsdatum, GBOX *gbox, lwflags_t *flags, uint8_t *type, int32_t *srid)
Peak into a GSERIALIZED datum to find its bounding box and some other metadata.
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:322
#define LW_FAILURE
Definition: liblwgeom.h:110
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
#define LINETYPE
Definition: liblwgeom.h:117
uint16_t lwflags_t
Definition: liblwgeom.h:313
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:179
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:59
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:180
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
Definition: lwgeom.c:738
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
Definition: ptarray.c:147
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
LWGEOM * lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition: lwgeom.c:2111
type
Definition: ovdump.py:42
tuple res
Definition: window.py:79
double ymax
Definition: liblwgeom.h:371
double zmax
Definition: liblwgeom.h:373
double xmax
Definition: liblwgeom.h:369
double zmin
Definition: liblwgeom.h:372
double mmax
Definition: liblwgeom.h:375
double ymin
Definition: liblwgeom.h:370
double xmin
Definition: liblwgeom.h:368
double mmin
Definition: liblwgeom.h:374
int32_t srid
Definition: liblwgeom.h:474
lwflags_t flags
Definition: liblwgeom.h:475
double m
Definition: liblwgeom.h:428
double x
Definition: liblwgeom.h:428
double z
Definition: liblwgeom.h:428
double y
Definition: liblwgeom.h:428

References LWGEOM::flags, FLAGS_GET_M, FLAGS_GET_Z, gserialized_datum_get_internals_p(), LINETYPE, LW_FAILURE, LW_TRUE, lwgeom_calculate_gbox(), lwgeom_construct_empty(), lwgeom_free(), lwgeom_from_gserialized(), lwline_as_lwgeom(), lwline_construct(), POINT4D::m, GBOX::mmax, GBOX::mmin, ptarray_append_point(), ptarray_construct_empty(), window::res, LWGEOM::srid, ovdump::type, POINT4D::x, GBOX::xmax, GBOX::xmin, POINT4D::y, GBOX::ymax, GBOX::ymin, POINT4D::z, GBOX::zmax, and GBOX::zmin.

Here is the call graph for this function: