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

◆ ST_BoundingDiagonal()

Datum ST_BoundingDiagonal ( PG_FUNCTION_ARGS  )

Definition at line 2902 of file lwgeom_functions_basic.c.

2903{
2904 GSERIALIZED *geom_in = PG_GETARG_GSERIALIZED_P(0);
2905 GSERIALIZED *geom_out;
2906 bool fits = PG_GETARG_BOOL(1);
2907 LWGEOM *lwgeom_in = lwgeom_from_gserialized(geom_in);
2908 LWGEOM *lwgeom_out;
2909 const GBOX *gbox;
2910 int hasz = FLAGS_GET_Z(lwgeom_in->flags);
2911 int hasm = FLAGS_GET_M(lwgeom_in->flags);
2912 int32_t srid = lwgeom_in->srid;
2913 POINT4D pt;
2914 POINTARRAY *pa;
2915
2916 if (fits)
2917 {
2918 /* unregister any cached bbox to ensure it's recomputed */
2919 lwgeom_in->bbox = NULL;
2920 }
2921
2922 gbox = lwgeom_get_bbox(lwgeom_in);
2923
2924 if (!gbox)
2925 {
2926 lwgeom_out = lwgeom_construct_empty(LINETYPE, srid, hasz, hasm);
2927 }
2928 else
2929 {
2930 pa = ptarray_construct_empty(hasz, hasm, 2);
2931 pt.x = gbox->xmin;
2932 pt.y = gbox->ymin;
2933 pt.z = gbox->zmin;
2934 pt.m = gbox->mmin;
2935 ptarray_append_point(pa, &pt, LW_TRUE);
2936 pt.x = gbox->xmax;
2937 pt.y = gbox->ymax;
2938 pt.z = gbox->zmax;
2939 pt.m = gbox->mmax;
2940 ptarray_append_point(pa, &pt, LW_TRUE);
2941 lwgeom_out = lwline_as_lwgeom(lwline_construct(srid, NULL, pa));
2942 }
2943
2944 lwgeom_free(lwgeom_in);
2945 PG_FREE_IF_COPY(geom_in, 0);
2946
2947 geom_out = geometry_serialize(lwgeom_out);
2948 lwgeom_free(lwgeom_out);
2949
2950 PG_RETURN_POINTER(geom_out);
2951}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1138
#define LINETYPE
Definition liblwgeom.h:117
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:179
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition lwline.c:42
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition lwgeom.c:321
#define FLAGS_GET_M(flags)
Definition liblwgeom.h:180
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:2083
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:107
const GBOX * lwgeom_get_bbox(const LWGEOM *lwgeom)
Get a non-empty geometry bounding box, computing and caching it if not already there.
Definition lwgeom.c:725
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
double ymax
Definition liblwgeom.h:343
double zmax
Definition liblwgeom.h:345
double xmax
Definition liblwgeom.h:341
double zmin
Definition liblwgeom.h:344
double mmax
Definition liblwgeom.h:347
double ymin
Definition liblwgeom.h:342
double xmin
Definition liblwgeom.h:340
double mmin
Definition liblwgeom.h:346
GBOX * bbox
Definition liblwgeom.h:444
int32_t srid
Definition liblwgeom.h:446
lwflags_t flags
Definition liblwgeom.h:447
double m
Definition liblwgeom.h:400
double x
Definition liblwgeom.h:400
double z
Definition liblwgeom.h:400
double y
Definition liblwgeom.h:400

References LWGEOM::bbox, LWGEOM::flags, FLAGS_GET_M, FLAGS_GET_Z, geometry_serialize(), LINETYPE, LW_TRUE, lwgeom_construct_empty(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_get_bbox(), 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: