PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ ST_BoundingDiagonal()

Datum ST_BoundingDiagonal ( PG_FUNCTION_ARGS  )

Definition at line 2909 of file lwgeom_functions_basic.c.

2910 {
2911  GSERIALIZED *geom_out;
2912  bool fits = PG_GETARG_BOOL(1);
2913  LWGEOM *lwgeom_out = NULL;
2914 
2915  GBOX gbox = {0};
2916  int hasz;
2917  int hasm;
2918  int32_t srid;
2919 
2920  POINT4D pt;
2921  POINTARRAY *pa;
2922 
2923  if (fits)
2924  {
2925  GSERIALIZED *geom_in = PG_GETARG_GSERIALIZED_P(0);
2926  LWGEOM *lwgeom_in = lwgeom_from_gserialized(geom_in);
2927  lwgeom_calculate_gbox(lwgeom_in, &gbox);
2928  hasz = FLAGS_GET_Z(lwgeom_in->flags);
2929  hasm = FLAGS_GET_M(lwgeom_in->flags);
2930  srid = lwgeom_in->srid;
2931  }
2932  else
2933  {
2934  uint8_t type;
2935  lwflags_t flags;
2936  int res = gserialized_datum_get_internals_p(PG_GETARG_DATUM(0), &gbox, &flags, &type, &srid);
2937  hasz = FLAGS_GET_Z(flags);
2938  hasm = FLAGS_GET_M(flags);
2939  if (res == LW_FAILURE)
2940  {
2941  lwgeom_out = lwgeom_construct_empty(LINETYPE, srid, hasz, hasm);
2942  }
2943  }
2944 
2945  if (!lwgeom_out)
2946  {
2947  pa = ptarray_construct_empty(hasz, hasm, 2);
2948  pt.x = gbox.xmin;
2949  pt.y = gbox.ymin;
2950  pt.z = gbox.zmin;
2951  pt.m = gbox.mmin;
2952  ptarray_append_point(pa, &pt, LW_TRUE);
2953  pt.x = gbox.xmax;
2954  pt.y = gbox.ymax;
2955  pt.z = gbox.zmax;
2956  pt.m = gbox.mmax;
2957  ptarray_append_point(pa, &pt, LW_TRUE);
2958  lwgeom_out = lwline_as_lwgeom(lwline_construct(srid, NULL, pa));
2959  }
2960 
2961  geom_out = geometry_serialize(lwgeom_out);
2962  lwgeom_free(lwgeom_out);
2963 
2964  PG_RETURN_POINTER(geom_out);
2965 }
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:2082
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: