PostGIS 3.6.2dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ ST_BoundingDiagonal()

Datum ST_BoundingDiagonal ( PG_FUNCTION_ARGS  )

Definition at line 3103 of file lwgeom_functions_basic.c.

3104{
3105 GSERIALIZED *geom_out;
3106 bool fits = PG_GETARG_BOOL(1);
3107 LWGEOM *lwgeom_out = NULL;
3108
3109 GBOX gbox = {0};
3110 int hasz;
3111 int hasm;
3112 int32_t srid;
3113
3114 POINT4D pt;
3115 POINTARRAY *pa;
3116
3117 if (fits)
3118 {
3119 GSERIALIZED *geom_in = PG_GETARG_GSERIALIZED_P(0);
3120 LWGEOM *lwgeom_in = lwgeom_from_gserialized(geom_in);
3121 lwgeom_calculate_gbox(lwgeom_in, &gbox);
3122 hasz = FLAGS_GET_Z(lwgeom_in->flags);
3123 hasm = FLAGS_GET_M(lwgeom_in->flags);
3124 srid = lwgeom_in->srid;
3125 }
3126 else
3127 {
3128 uint8_t type;
3129 lwflags_t flags;
3130 int res = gserialized_datum_get_internals_p(PG_GETARG_DATUM(0), &gbox, &flags, &type, &srid);
3131 hasz = FLAGS_GET_Z(flags);
3132 hasm = FLAGS_GET_M(flags);
3133 if (res == LW_FAILURE)
3134 {
3135 lwgeom_out = lwgeom_construct_empty(LINETYPE, srid, hasz, hasm);
3136 }
3137 }
3138
3139 if (!lwgeom_out)
3140 {
3141 pa = ptarray_construct_empty(hasz, hasm, 2);
3142 pt.x = gbox.xmin;
3143 pt.y = gbox.ymin;
3144 pt.z = gbox.zmin;
3145 pt.m = gbox.mmin;
3146 ptarray_append_point(pa, &pt, LW_TRUE);
3147 pt.x = gbox.xmax;
3148 pt.y = gbox.ymax;
3149 pt.z = gbox.zmax;
3150 pt.m = gbox.mmax;
3151 ptarray_append_point(pa, &pt, LW_TRUE);
3152 lwgeom_out = lwline_as_lwgeom(lwline_construct(srid, NULL, pa));
3153 }
3154
3155 geom_out = geometry_serialize(lwgeom_out);
3156 lwgeom_free(lwgeom_out);
3157
3158 PG_RETURN_POINTER(geom_out);
3159}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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.
#define LW_FAILURE
Definition liblwgeom.h:96
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1218
#define LINETYPE
Definition liblwgeom.h:103
uint16_t lwflags_t
Definition liblwgeom.h:299
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_Z(flags)
Definition liblwgeom.h:165
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition lwline.c:42
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition lwgeom.c:339
#define FLAGS_GET_M(flags)
Definition liblwgeom.h:166
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
LWGEOM * lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition lwgeom.c:2191
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:93
tuple res
Definition window.py:79
double ymax
Definition liblwgeom.h:357
double zmax
Definition liblwgeom.h:359
double xmax
Definition liblwgeom.h:355
double zmin
Definition liblwgeom.h:358
double mmax
Definition liblwgeom.h:361
double ymin
Definition liblwgeom.h:356
double xmin
Definition liblwgeom.h:354
double mmin
Definition liblwgeom.h:360
int32_t srid
Definition liblwgeom.h:460
lwflags_t flags
Definition liblwgeom.h:461
double m
Definition liblwgeom.h:414
double x
Definition liblwgeom.h:414
double z
Definition liblwgeom.h:414
double y
Definition liblwgeom.h:414

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(), LWGEOM::srid, 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: