PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ST_BoundingDiagonal()

Datum ST_BoundingDiagonal ( PG_FUNCTION_ARGS  )

Definition at line 3138 of file lwgeom_functions_basic.c.

3139 {
3140  GSERIALIZED *geom_out;
3141  bool fits = PG_GETARG_BOOL(1);
3142  LWGEOM *lwgeom_out = NULL;
3143 
3144  GBOX gbox = {0};
3145  int hasz;
3146  int hasm;
3147  int32_t srid;
3148 
3149  POINT4D pt;
3150  POINTARRAY *pa;
3151 
3152  if (fits)
3153  {
3154  GSERIALIZED *geom_in = PG_GETARG_GSERIALIZED_P(0);
3155  LWGEOM *lwgeom_in = lwgeom_from_gserialized(geom_in);
3156  lwgeom_calculate_gbox(lwgeom_in, &gbox);
3157  hasz = FLAGS_GET_Z(lwgeom_in->flags);
3158  hasm = FLAGS_GET_M(lwgeom_in->flags);
3159  srid = lwgeom_in->srid;
3160  }
3161  else
3162  {
3163  uint8_t type;
3164  lwflags_t flags;
3165  int res = gserialized_datum_get_internals_p(PG_GETARG_DATUM(0), &gbox, &flags, &type, &srid);
3166  hasz = FLAGS_GET_Z(flags);
3167  hasm = FLAGS_GET_M(flags);
3168  if (res == LW_FAILURE)
3169  {
3170  lwgeom_out = lwgeom_construct_empty(LINETYPE, srid, hasz, hasm);
3171  }
3172  }
3173 
3174  if (!lwgeom_out)
3175  {
3176  pa = ptarray_construct_empty(hasz, hasm, 2);
3177  pt.x = gbox.xmin;
3178  pt.y = gbox.ymin;
3179  pt.z = gbox.zmin;
3180  pt.m = gbox.mmin;
3181  ptarray_append_point(pa, &pt, LW_TRUE);
3182  pt.x = gbox.xmax;
3183  pt.y = gbox.ymax;
3184  pt.z = gbox.zmax;
3185  pt.m = gbox.mmax;
3186  ptarray_append_point(pa, &pt, LW_TRUE);
3187  lwgeom_out = lwline_as_lwgeom(lwline_construct(srid, NULL, pa));
3188  }
3189 
3190  geom_out = geometry_serialize(lwgeom_out);
3191  lwgeom_free(lwgeom_out);
3192 
3193  PG_RETURN_POINTER(geom_out);
3194 }
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:96
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
#define LINETYPE
Definition: liblwgeom.h:103
uint16_t lwflags_t
Definition: liblwgeom.h:299
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:165
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: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
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
LWGEOM * lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition: lwgeom.c:2105
type
Definition: ovdump.py:42
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(), 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: