PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ ST_BoundingDiagonal()

Datum ST_BoundingDiagonal ( PG_FUNCTION_ARGS  )

Definition at line 3021 of file lwgeom_functions_basic.c.

3022 {
3023  GSERIALIZED *geom_out;
3024  bool fits = PG_GETARG_BOOL(1);
3025  LWGEOM *lwgeom_out = NULL;
3026 
3027  GBOX gbox = {0};
3028  int hasz;
3029  int hasm;
3030  int32_t srid;
3031 
3032  POINT4D pt;
3033  POINTARRAY *pa;
3034 
3035  if (fits)
3036  {
3037  GSERIALIZED *geom_in = PG_GETARG_GSERIALIZED_P(0);
3038  LWGEOM *lwgeom_in = lwgeom_from_gserialized(geom_in);
3039  lwgeom_calculate_gbox(lwgeom_in, &gbox);
3040  hasz = FLAGS_GET_Z(lwgeom_in->flags);
3041  hasm = FLAGS_GET_M(lwgeom_in->flags);
3042  srid = lwgeom_in->srid;
3043  }
3044  else
3045  {
3046  uint8_t type;
3047  lwflags_t flags;
3048  int res = gserialized_datum_get_internals_p(PG_GETARG_DATUM(0), &gbox, &flags, &type, &srid);
3049  hasz = FLAGS_GET_Z(flags);
3050  hasm = FLAGS_GET_M(flags);
3051  if (res == LW_FAILURE)
3052  {
3053  lwgeom_out = lwgeom_construct_empty(LINETYPE, srid, hasz, hasm);
3054  }
3055  }
3056 
3057  if (!lwgeom_out)
3058  {
3059  pa = ptarray_construct_empty(hasz, hasm, 2);
3060  pt.x = gbox.xmin;
3061  pt.y = gbox.ymin;
3062  pt.z = gbox.zmin;
3063  pt.m = gbox.mmin;
3064  ptarray_append_point(pa, &pt, LW_TRUE);
3065  pt.x = gbox.xmax;
3066  pt.y = gbox.ymax;
3067  pt.z = gbox.zmax;
3068  pt.m = gbox.mmax;
3069  ptarray_append_point(pa, &pt, LW_TRUE);
3070  lwgeom_out = lwline_as_lwgeom(lwline_construct(srid, NULL, pa));
3071  }
3072 
3073  geom_out = geometry_serialize(lwgeom_out);
3074  lwgeom_free(lwgeom_out);
3075 
3076  PG_RETURN_POINTER(geom_out);
3077 }
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:339
#define LW_FAILURE
Definition: liblwgeom.h:111
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
#define LINETYPE
Definition: liblwgeom.h:118
uint16_t lwflags_t
Definition: liblwgeom.h:314
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:180
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:181
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:755
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:108
LWGEOM * lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition: lwgeom.c:2128
type
Definition: ovdump.py:42
tuple res
Definition: window.py:79
double ymax
Definition: liblwgeom.h:372
double zmax
Definition: liblwgeom.h:374
double xmax
Definition: liblwgeom.h:370
double zmin
Definition: liblwgeom.h:373
double mmax
Definition: liblwgeom.h:376
double ymin
Definition: liblwgeom.h:371
double xmin
Definition: liblwgeom.h:369
double mmin
Definition: liblwgeom.h:375
int32_t srid
Definition: liblwgeom.h:475
lwflags_t flags
Definition: liblwgeom.h:476
double m
Definition: liblwgeom.h:429
double x
Definition: liblwgeom.h:429
double z
Definition: liblwgeom.h:429
double y
Definition: liblwgeom.h:429

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: